
1、构造函数有原型对象,原型对象有指针指向结构函数,每个实例都有内部指针指向原型对象。
2、Father通过new给Children的原型对象赋值一个实例,从而实现Children继承Father。
实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | function Father() {
this .name = "father"
this .house = "cottage"
}
Father.prototype.alertName = function () {
console.log( this .name)
}
let f = new Father()
f.alertName()
function Children() {
this .name = "children"
}
Children.prototype = new Father()
let c = new Children()
c.alertName()
console.log(c.house)
|
以上就是js原型链继承的关系,希望对大家有所帮助。更多js学习指路:js教程
推荐操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。