JavaScript: Object.defineProperties

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

// add 2 properties, with their attributes
Object.defineProperties(
yy,
{
x1:{ value : 1, writable: true, enumerable: true, configurable: true},
x2:{ value : 2, writable: true, enumerable: true, configurable: true}
}
);

console.log(yy); // { x1: 1, x2: 2 }

JavaScript Define Properties

BUY ΣJS JavaScript in Depth