function person(params) { console.log(this.fs); }person.prototype.say = function () { console.log(this);};Function.prototype.say = 'say'person.say; // sayperson();var a = {}a.prototype.hand = function () { console.log('haha');}a.hand(); // throw error, why?lz當然知道沒有實例化,但問題主要是這兩個:這里為什么不會沿著原型鏈向上找呢? 為什么實例化之后就能從原型鏈上找,未實例化就不行?同時,我們打出來 person.prototype 是能看到它的原型的。 我同時又定義了 Function.prototype.say = 'say' 之后, person.say 就有了結果? 為什么不讀取自己的 prototype 而是讀取 constructor 的 prototype呢?
關于js原型鏈的一個問題
蕪湖不蕪
2018-12-27 22:13:43