function person(params) {
console.log(this.fs);
}
person.prototype.say = function () {
console.log(this);
};
Function.prototype.say = 'say'
person.say; // say
person();
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
呢?
长风秋雁
相关分类