JS: Object.defineProperties

By Xah Lee. Date: . Last updated: .
Object.defineProperties(obj, {key1: descriptor1}, {key2: descriptor2}, etc)
  • Create or modify one or more properties.
  • Return the modified obj.
  • The descriptor1, descriptor2, etc are Property Descriptor.
const xx = {};

// add 2 properties with attributes
Object.defineProperties(
 xx,
 {
  paa: { value: 1, writable: true, enumerable: true, configurable: true },
  pbb: { value: 2, writable: true, enumerable: true, configurable: true },
 },
);

console.log(xx);
// { paa: 1, pbb: 2 }

JavaScript. Define Properties and attributes.