原型链练习

作业 画出原型链

//动物--->人---->老师---->坏老师

function Animal(){
this.gender = "male";
}

var animal=new Animal();//实例化
Human.prototype = new Animal();
Human.prototype.constructor = Human;

function Human(){
this.actionWay = "走路";
}

Teacher.prototype = new Human();
Teacher.prototype.constructor = Teacher;
function Teacher(){
this.skill = "教书";
}

BadTeacher.prototype = new Teacher();
BadTeacher.prototype.constructor = BadTeacher;
function BadTeacher(){
this.name = "俞敏洪";
}

var t = new BadTeacher();
console.log(t);
console.log(t.name);
console.log(t.skill);
console.log(t.actionWay);

猜你喜欢

转载自www.cnblogs.com/vzaiBoke/p/9105810.html