javascript原型链同名方法不是从最近的取吗?


function Q() {
  this.subproperty = false;
  this.getSuperValue = function() {
    return this.property;
  }
}
function QQ() {
  this.property = true;
}
Q.prototype = new QQ(); 

var instance = new Q();
console.log(instance.getSuperValue()); // true

这里为什么输出 true 呢?

false 不是更近一点吗?

阅读 1.9k
2 个回答

因为你写错了啊。

 this.subproperty = false;

应该是

 this.property = false;

你的 property 只声明了一次,就是 true

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题