JavaScript: Reflect.defineProperty

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.defineProperty(obj, key, descriptor)
Create/modify a property's attributes by Property Descriptor.
Return true if successful, else false.
(Object.defineProperty return the modified object)
// example of creating or changing a property attribute

const jj = {};

const yy = Reflect.defineProperty(jj, "kk", {
  value: 3,
  writable: true,
  enumerable: false,
  configurable: true,
});

console.log(jj.kk === 3);
console.log(jj.propertyIsEnumerable("kk") === false);

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

JavaScript Define Properties

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Reflect