1// hasOwnProperty – JavaScript does not protect
2var foo = {
3 // overriding foo's default hasOwnProperty method
4 hasOwnProperty: function() {
5 return false;
6 },
7 bar: 'data'
8};
9foo.hasOwnProperty('bar'); // false always
10
11// Hence, to prevent this, use Object.prototype.hasOwnProperty as follows-
12Object.prototype.hasOwnProperty.call(foo, 'bar'); // true