Whats the use of prototype keyword?


#1


14. prototype to the rescue


if i use the below cod, it still works! so what is the use of prototype????


Dog.bark = function () {
console.log("Woof");
};
 
 instead of

Dog.prototype.bark = function () {
console.log("Woof");
};


#2

That code would never be used. And, neither would this,

Instead we would pass everything up to the caller.

function Dog() {

}
Dog.prototype.bark = function () {
    return "Woof";
};
(new Dog()).bark();

=> 'Woof'

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.