玩笑过后

导航

继承方法-->原型的相互引用

        function Father(){}
        Father.prototype.name = 'zhang';
        function Son(){}
        function inherit(Target,Orgin){
            Target.prototype = Orgin.prototype;
        }
        inherit(Son,Father);
        var son = new Son();
        var father = new Father;
        console.log(son.name);
        console.log(father.name);
        Son.prototype.sex = 'nan';
        console.log(son.sex);
        console.log(father.sex);

由于prototype指向到同一个对象,所以无论谁改变了内在属性,

都会统一改变;

不能保持对象原型的独立性

 

posted on 2018-06-27 16:30  玩笑过后  阅读(103)  评论(0编辑  收藏  举报