Skip to content

Instantly share code, notes, and snippets.

@gbhasha
Forked from quisido/has-own-property.js
Created October 3, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbhasha/66c23560362bd88f86c0c142a1347588 to your computer and use it in GitHub Desktop.
Save gbhasha/66c23560362bd88f86c0c142a1347588 to your computer and use it in GitHub Desktop.
Object.prototype.hasOwnProperty.call
const myObject = Object.create(null);
myObject; // {}
myObject.test; // undefined
Object.prototype.hasOwnProperty.call(myObject, 'test'); // false
// Uncaught TypeError:
// myObject.hasOwnProperty is not a function
myObject.hasOwnProperty('test');
myObject.test = true;
myObject; // { test: true }
myObject.test; // true
Object.prototype.hasOwnProperty.call(myObject, 'test'); // true
// Uncaught TypeError:
// myObject.hasOwnProperty is not a function
myObject.hasOwnProperty('test');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment