上面是代码,想执行'person1.func3()'。
结果如下图
疑问是,在实例对象person1的__proto__里能找到func3这个函数,为什么执行的时候会报错呢?
谢谢!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Person.prototype.func3 = function () {
console.log('this is func3')
};
好像通过 实例.prototype 添加方法的话就能访问了。。。
为什么必须使用 prototype 添加才好使呢。。。
你的
func3
是挂在constructor
下面的,只是Person
这个构造器的一个属性而已,和Prototype
无关而正常的原型链方法应该是挂在
[[Prototype]]
下面的要挂在原型下面才能被原型链找到使用。