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, but 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

back to JS: Reflect

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials