Skip to content

Instantly share code, notes, and snippets.

@singhArmani
Created March 21, 2019 03:34
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 singhArmani/4002096038805c74df0ea060bf88628e to your computer and use it in GitHub Desktop.
Save singhArmani/4002096038805c74df0ea060bf88628e to your computer and use it in GitHub Desktop.
var obj = { a: 1, b: 2 }; // a, b are both enumerables properties
// setting {c: 3} as the prototype of 'obj',
// and as we know for-in loop also iterates over the properties obj inherits
// from its prototype, 'c' will also be visited.
Object.setPrototypeOf(obj, { c: 3 });
// we are defining one more property 'd' into our 'obj',
// but we are setting the 'enumerable' to false. It means 'd' will be ignored.
Object.defineProperty(obj, "d", { value: 4, enumerable: false });
for (let prop in obj) {
console.log(prop);
}
// it will print
// a
// b
// c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment