Created
March 21, 2019 03:34
-
-
Save singhArmani/4002096038805c74df0ea060bf88628e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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