Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

hasownproperty

// JavaScript does not protect hasOwnProperty method
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
 
PREVIOUS NEXT
Tagged: #hasownproperty
ADD COMMENT
Topic
Name
6+7 =