
1、构造函数有原型对象,原型对象有指针指向结构函数,每个实例都有内部指针指向原型对象。
2、Father通过new给Children的原型对象赋值一个实例,从而实现Children继承Father。
实例
//父构造函数
functionFather(){
this.name="father"
this.house="cottage"
}
//原型方法
Father.prototype.alertName=function(){
console.log(this.name)
}
//创造实例
letf=newFather()
f.alertName()//father
//子构造函数
functionChildren(){
this.name="children"
}
//实现继承:子构造函数的原型对象=父构造函数的实例对象
Children.prototype=newFather()
//创建子实例
letc=newChildren()
//儿子就继承了父亲的所有属性(大别墅),并且获得了自己的名字
c.alertName()//children
console.log(c.house)//cottage
以上就是js原型链继承的关系,希望对大家有所帮助。更多js学习指路:js教程
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容