Last active
February 21, 2022 16:51
-
-
Save blarfoon/e0488a6856f29374fb997ffaa2914042 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const myObject = {}; | |
Object.defineProperty(myObject, "hi", { | |
value: "mom", | |
writable: true, // default: false | |
enumerable: true, // default: false | |
configurable: true, // default: false | |
}); | |
console.log(myObject.hi); // > mom | |
myObject.hi = "medium"; | |
console.log(myObject.hi); // > medium | |
delete myObject.hi; | |
console.log(myObject.hi); // > undefined | |
Object.defineProperty(myObject, "hi", { | |
value: "mom", | |
writable: true, // default: false | |
enumerable: true, // default: false | |
configurable: true, // default: false | |
}); | |
console.log(myObject.hi); // > mom | |
Object.defineProperty(myObject, "hello", { | |
value: "world", | |
writable: false, // default: false | |
enumerable: false, // default: false | |
configurable: false, // default: false | |
}); | |
console.log(myObject.hello); // > world | |
myObject.hello = "medium"; | |
console.log(myObject.hello); // > world | |
delete myObject.hello; | |
console.log(myObject.hello); // > world | |
// > Uncaught TypeError: Cannot redefine property: hello at Function.defineProperty (<anonymous>) | |
Object.defineProperty(myObject, "hello", { | |
value: "medium", | |
writable: false, // default: false | |
enumerable: false, // default: false | |
configurable: false, // default: false | |
}); | |
console.log(myObject.hello); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment