function foo(name) {
this.name = name;
}
foo.prototype.getName = function() {
return `Hello ${this.name}!`;
}
function bar(name) {
foo.call(this, name);
this.name = name;
}
bar.prototype = Object.create(foo.prototype);
// bar.prototype = new foo();
// bar.prototype = Object.create(new foo());
bar.prototype.constructor = bar;
var b = new bar('John Doe');
console.log(b.getName());
What is the difference between these three ways?
bar.prototype = Object.create(foo.prototype);
bar.prototype = new foo();
bar.prototype = Object.create(new foo());