Object.getOwnPropertyDescriptor & Object.defineProperty Methods.
1) Property Descriptor: When we create a JavaScript object, whether using object literal syntax or some other means and add some properties to it, each property (key) gets a default property descriptor. A property descriptor is a simple JavaScript object associated with each property of the object that contains information about that property such as its value and other meta-data. 2) Access Property Descriptor: We need to use a static method provided by the Object. The Object.getOwnPropertyDescriptor method returns the property descriptor of the "prop" which is the property name on the "obj" object. Object.getOwnPropertyDescriptor(obj, prop); Own here means return the property descriptor of prop property only if that property belongs to the object obj and not on its prototype chain. If the property prop doesn’t exist on obj, it returns undefined. The Object.getOwnPropertyDescriptor method returns an object with keys describing the setting and current value of th...
Comments
Post a Comment