// 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