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


ECMAScript® 2016 Language Specification#sec-reflect.defineproperty

back to JS: Reflect

Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

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

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog