JS: Reflect.defineProperty

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.defineProperty(obj, key, descriptor)
Create or modify a property's attributes by Property Descriptor.
Return true if successful, else false.
// 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