Skip to content

Instantly share code, notes, and snippets.

@jmwebservices
Last active March 20, 2019 20:09
Show Gist options
  • Save jmwebservices/6f679c459af662557fd7ae82cf05756e to your computer and use it in GitHub Desktop.
Save jmwebservices/6f679c459af662557fd7ae82cf05756e to your computer and use it in GitHub Desktop.
JavaScript Own vs Proto vs [Non-]Enumerable Getters

JavaScript Property Type Getters

Use the following table as a desk reference for the various ways to obtain properties of objects and which properties each method returns.

Method/Operator/Loop own proto enumerable non-enumerable
for prop in obj ✔️ ✔️ ✔️
prop in obj ✔️ ✔️ ✔️ ✔️
obj.hasOwnProperty( prop ) ✔️ ✔️ ✔️
obj.propertyIsEnumerable( prop ) ✔️ ✔️
Object.assign( targetObj, ...obj ) ✔️ ✔️
Object.getOwnPropertyNames( obj ) ✔️ ✔️ ✔️
Object.keys( obj ) ✔️ ✔️
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment