我试图学习如何在JavaScript中的object.prototype函数,然后我遇到了这段代码。我不明白?JavaScript对象原型中毒
// Poisoning Object.prototype
Object.prototype.bar = 1;
var foo = {goo: undefined};
foo.bar; // 1
'bar' in foo; // true
foo.hasOwnProperty('bar'); // false
foo.hasOwnProperty('goo'); // true
FOO具有在行号3中定义和属性栏具有未定义的。请导的值,那么为什么foo.hasOwnProperty('bar')
返回false
在这种情况下
最好阅读MDN [关于hasOwnProperty的文档](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) –
它没有*它*它,它*继承*它。这就是原型的全部意义。 – Bergi