js對(duì)象生成時(shí):
如:function BB(a){
this.a="kkk"
}
var b=new BB();
這時(shí)b是對(duì)象有了BB的的屬性prototype所指向的prototype對(duì)象;
prototype對(duì)象有constructor屬性指向BB這個(gè)函數(shù);
所以alert(b.constructor==BB.prototype.constructor) //true
這里的“有了”的執(zhí)行過(guò)程是先查看b有沒(méi)有此屬性讓后去查看prototype里的屬性值,不是簡(jiǎn)單的A=B:
如添加:b.constructor="ccc";
執(zhí)行:alert(b.constructor==BB.prototype.constructor) //false; BB.prototype.constructor仍然是BB函數(shù);
看一下taobao的kissy的繼承:
F.prototype = o;
return new F();
},
sp = s.prototype,
rp = O(sp);
r.prototype = rp;
//alert(r.prototype.constructor==sp.constructor)
rp.constructor = r;
//alert(r.prototype.constructor==sp.constructor)
r.superclass = sp;
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注