
1、默认情况下,所有引用类型值都继承了Object,这种继承也是通过原型链实现的。
2、所有函数的默认原型都是Object的实例,所以默认原型包含一个内部指针,指向Object.prototype。
实例
//父构造函数
functionFather(){
this.name="father"
this.house="cottage"
}
//原型方法
Father.prototype.alertName=function(){
console.log(this.name)
}
//子构造函数
functionChildren(){
this.name="children"
}
//实现继承:子构造函数的原型对象=父构造函数的实例对象
Children.prototype=newFather()
//创建子实例
letc=newChildren()
//使用Object原型上的方法
console.log(c.hasOwnProperty('name'))//true
以上就是js原型链默认的原型,希望对大家有所帮助。更多js学习指路:js教程
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容