Common Misconceptions About Inheritance in JavaScript
Eric Elliott
2.3K68

Can I ask a stupid question, I just could not find the answer. Are those obj1 and obj2 the same below:

var obj1 = {
name: 'peter',
printName: function(){
console.log(this.name);
}
}

and

var OBJ = function(_name){
this.name = _name;
}
OBJ.prototype.printName = function(){
console.log(this.name);
}
var obj2 = new OBJ('peter);
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.