撸一遍继续

function aa(x){
    this.x=x;
    this.sayx=function(){
        console.log(x);
    }
}
aa.prototype = {
    do:function(){
        console.log("嘟嘟")
    }
}
function bb(y,x){
    this.y=y;
    aa.call(this,x);
}
//bb.prototype = Object.create(aa);
bb.prototype = Object.create(aa.prototype);
//bb.prototype = aa.prototype;
//bb.prototype = new aa();
/*割了*/
//var f = funciton(){};
//f.prototype = aa.prototype;//或许new
//bb.prototype = new f();
//bb.prototype = new aa("ccc");
bb.prototype.do1=function(){
    console.log("嘟嘟1");
}
bb.prototype.constructor=bb;
var cc = new bb("aa","bb");
console.dir(cc);

总之一句话,原型链就是把一个对象连接到另一个对象到另一个对象….
对prototype赋值对象会损坏组织函数,prototype.dosthing如许能够避免掉。
prototype.proto

    原文作者:代码碎片
    原文地址: https://segmentfault.com/a/1190000002401554
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞