i am a newbie to Js OOp.
I was reading somewhere that Prototypes are used in OOP
in JS
Ok here is an example
function Dog(name) {
this.name = name;
this.age = age;
this.bark = function() {
console.log("Woof");
}
}
Now my question is why can't we just create objects like this
Dog doberman = new Dog;
This creates a new Dog object.
But through prototypes we do something like this
var doberman = Object.create(dog);
I read that the functions can be separated and through prototype they can be added to the object. Please help me. I am confused..
Well the question simply is Why use Object.prototype for methods?