...
/Solution Review: Prototypal Inheritance
Solution Review: Prototypal Inheritance
This lesson will explain the solution to the problem in the previous lesson.
We'll cover the following...
Solution #
Press + to interact
function Human(name, age) {this.name = name;this.age = age;};function Man(name,age) {Human.call(this, name, age);};Man.prototype = Object.create(Human.prototype);Man.prototype.constructor = Man;function check(){var obj = new Man("Tommy Tan",20);console.log(obj.name)console.log(obj instanceof Human)}check()
Explanation #
In the code above, Human
is the parent from which the child, Man
, inherits. For it to inherit the ...