JS: Reflect.defineProperty

By Xah Lee. Date: . Last updated: .

New in ES2015.

Reflect.defineProperty ( obj, key, attributes )

Create a property with specified attribute values, or modify a existing property's attributes.

Return true if successful, else false.

Similar to Object.defineProperty, except here it returns the object or throw error.

[see JS: Object.defineProperty]

[see JS: Property Attributes, writable, enumerable, configurable]

const u = {};

const result = Reflect.defineProperty(u, "p",
{ value : 3,
  writable: true,
  enumerable: true,
  configurable: true
}
);

console.log( u ); // { p: 3 }

// return value is true/false
console.log( result ); // true

Reference

ECMAScript® 2016 Language Specification#sec-reflect.defineproperty

back to JS: Reflect Object

Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon