首页 > 编程语言 > 详细

JavaScript 原型链

时间:2019-10-30 00:17:33      阅读:74      评论:0      收藏:0      [点我收藏+]

原型链笔记:

        function Grand(){}
        Grand.prototype.age="110";
        var grand=new Grand();
        
        function Father(){
            this.name="111";
        }
        Father.prototype=grand;
        var father=new Father();
        
        function Son(){
            this.color="red";
        }
        Son.prototype=father;
        var son=new Son();
            

通过设置prototype形成原型链,得到  son.name="111" 其余类似

踩坑:设置prototype一定要设置在调用构造函数之前,生成对象再设置原型是无法调用前面的属性的

增删改都只能自己弄,子孙不能

JavaScript 原型链

原文:https://www.cnblogs.com/tomatofjy/p/11761857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!