让子对象的原型指向父对象的实例,父对象的原型指向爷爷对象的实例,依次类推,就形成了原型链
function Animal(newAge){
this.age = newAge;
}
Animal.prototype.eat = function(){
console.log("Animal.eat");
}
function Person(newId){
this.id = newId;
}
Person.prototype = new Animal(18);
Person.prototype.study = function(){
console.log("Person.study");
}
function Pupli(newTall){
this.tall = newTall;
}
Pupli.prototype = new Person("007");
Pupli.prototype.play = function(){
console.log("Pupli.play");
}
let pu = new Pupli(140);
console.log(pu.age,pu.id,pu.tall);
pu.eat();
pu.study();
pu.play();