Well I am curios to learn about prototypes in javascript and found many articles however i am not able to understand why am i not able to use prototypes in Object literals in javascript. As we all know, everything is inherited from Object so in that case
function Dog() {
}
Dog.prototype = new Animal;
Dog.prototype.bark = function() {
console.log("Woof! My name is " + this.name);
};
If I am able to use prototype in the function why am i not able to use prototype in the object literals for instance the below example
var obj = {
firstname: 'foo',
lastname:'bar'
}
// this throws an error
obj.prototype.getMethod = function () {
console.log('this is a function');
}
I have gone through all this question but it really doesnt answer the reason why cant use prototype in the object literals in javascript. Below are some of the references