JS Built-ins
ObjectObject.definePropertiesbeginner

Object.defineProperties() β€” define multiple at once

πŸ“– Usage Example
// Define multiple property descriptors at once
const obj = {}
Object.defineProperties(obj, {
  x: { value: 1, writable: true, enumerable: true },
  y: { value: 2, writable: false, enumerable: true },
})

Use Object.defineProperties() to define multiple properties with fine-grained descriptors in a single call.

Object.defineProperties()

Object.defineProperties(obj, props) lets you define multiple properties in a single call, each with its own descriptor.

Challenge: Implement addMultiple(obj) that defines x (value: 1) and y (value: 2) on obj using Object.defineProperties.

const o = {}
addMultiple(o)
o.x // β†’ 1
o.y // β†’ 2
πŸ’‘ Hints (2)
  • β€’ `Object.defineProperties` takes a map where each value is a property descriptor.
  • β€’ Include `writable:true, enumerable:true, configurable:true` to behave like normal properties.