? function test(){? var a={};//創(chuàng)建一個(gè)空對(duì)象? a._proto_=test.prototype;//把a(bǔ)對(duì)象的內(nèi)置原型屬性設(shè)置為test的prototype? a.name="帥哥天下9";//給對(duì)象a 添加屬性? a.id="12";? return a; //返回對(duì)象a? }test.prototype.say=function(){
alert("cool");
}var a=test();console.log(a.say());//say not a functionconsole.log(a._proto_.say());//正確執(zhí)行我認(rèn)為 new 的過程就是上述test()的過程? 可是為什么方法不會(huì)通過原型鏈去找
JS new 的 問題
一人我編程累
2018-03-26 15:19:47