今天我注意到了hasOwnProperty方法的一些奇怪的行为。
我所在的环境完全支持ES6类,所以不需要担心转换。
上面的代码片段应该分别返回true和false,但这两个代码片段都返回true。
class Stuff {
constructor() { this.something = 'something'; }
}
class MoreStuff extends Stuff {}
const stuff = new Stuff();
const moreStuff = new MoreStuff();
console.log(Object.prototype.hasOwnProperty.call(stuff, 'something'));
console.log(Object.prototype.hasOwnProperty.call(moreStuff, 'something'));
也许我在这里遗漏了一些东西,但据我所知,东西上存在一些东西,它在moreStuff上继承了,但似乎两者都存在。我错过了什么?
https://stackoverflow.com/questions/56113060
复制相似问题