📅  最后修改于: 2022-03-11 15:01:22.631000             🧑  作者: Mango
// hasOwnProperty – JavaScript does not protect
var foo = {
// overriding foo's default hasOwnProperty method
hasOwnProperty: function() {
return false;
},
bar: 'data'
};
foo.hasOwnProperty('bar'); // false always
// Hence, to prevent this, use Object.prototype.hasOwnProperty as follows-
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true