JavaScript 原型链

原型链笔记:

        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一定要设置在调用构造函数之前,生成对象再设置原型是无法调用前面的属性的

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

posted @ 2019-10-29 21:58  邶森  阅读(110)  评论(0)    收藏  举报