关于js原型链的一个问题

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当然知道没有实例化,但问题主要是这两个:

  1. 这里为什么不会沿着原型链向上找呢? 为什么实例化之后就能从原型链上找,未实例化就不行?

  2. 同时,我们打出来 person.prototype 是能看到它的原型的。 我同时又定义了 Function.prototype.say = 'say' 之后, person.say 就有了结果? 为什么不读取自己的 prototype 而是读取 constructor 的 prototype呢?


芜湖不芜
浏览 455回答 1
1回答

长风秋雁

var person = new Person()//要实例化对象(另外类名一般要大写)person.say()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript