function A(name, gender) {
this.name = name;
this.gender = gender;
}
A.prototype.speak = function() {
alert('Calling from A ' + this.name);
};
function B(name, gender){
this.name = name;
this.gender = gender;
}
B.prototype.speak = function() {
alert('Calling from B ' + this.name);
};
B.prototype = Object.create(A.prototype);
B.prototype.constructor = B;
var b = new B('shane', 'M');
console.log(b);
b.speak();
- Why does the
prototype chain
looks at the parent prototype methods than looking at the Child prototype method? - Will my
instance b
only have theinstance propeties
andmethods
and not itsprototype methods
?
The code above prints "Calling from A Shane"
;