Created
October 11, 2017 17:33
-
-
Save prof3ssorSt3v3/b38039f992f9ab37f1e4c11350dbf65d 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
/*************************************** | |
Property Descriptors Methods and Usage | |
Object.defineProperty(obj, propName, {} ) | |
Object.defineProperties(obj, props) | |
Object.getOwnPropertyNames(obj) | |
Object.getOwnPropertyDescriptor(obj, prop) | |
Object.getOwnPropertyDescriptors(obj) | |
Object.keys(obj) - list of enumerable properties | |
Object.values(obj) - list of enumerable prop values | |
obj.propertyIsEnumerable(prop) | |
obj.hasOwnProperty(prop) | |
Objects can be | |
1. Extensible - new properties added | |
2. Frozen - props cannot be changed in any way | |
3. Sealed - props can't be deleted or configured | |
but are still writable | |
Object PROPERTIES can be | |
1. Writable - change the value | |
2. Enumerable - seen through a for...in loop | |
3. Configurable - change the property descriptors | |
Object.isExtensible(obj) | |
Object.isFrozen(obj) | |
Object.isSealed(obj) | |
Object.preventExtensions(obj) | |
Object.freeze(obj) | |
Object.seal(obj) | |
Descriptor Groups | |
DATA ACCESSOR | |
value get | |
writable set | |
configurable configurable | |
enumerable enumerable | |
****************************************/ | |
let log = console.log; | |
let obj = { | |
name: 'Bob', | |
age: 45 | |
}; | |
Object.defineProperty(obj, 'test', { | |
value: 'Shagadelic', | |
writable: true, | |
configurable: true, | |
enumerable: false | |
} ); | |
Object.defineProperty(obj, 'frank', { | |
configurable:true, | |
enumerable: true, | |
get: () => this.value, | |
set: (_val) => { | |
this.value = _val + " baby!"; | |
} | |
}); | |
for( let prop in obj){ | |
log(prop); | |
} | |
log( obj, obj.test, obj.frank ); | |
obj.frank = 'Shagadelic'; | |
log(obj.frank); | |
thanks
Perfect! Thanks for the awesome content!
Thanks and excellent
thank you
Priceless
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, It is very helpful!!