Sham for Reflect.defineProperty
This method allows precise addition to or modification of a property on an object. For more details see the Object.defineProperty which is similar. Object.defineProperty returns the object or throws a TypeError if the property has not been successfully defined. Reflect.defineProperty, however, simply returns a Boolean indicating whether or not the property was successfully defined.
Kind: Exported function
Returns: Object
- A Boolean indicating whether or not the property was successfully defined.
Throws:
TypeError
If target is not an Object.
Param | Type | Description |
---|---|---|
target | * |
The target object on which to define the property. |
propertyKey | * |
The name of the property to be defined or modified. |
attributes | * |
The attributes for the property being defined or modified. |
Example
import reflectDefineProperty from 'reflect-define-property-x';
const obj = {};
reflectDefineProperty(obj, 'x', {value: 7}); // true
console.log(obj.x); // 7