The Object.defineProperties() method defines new or modifies existing properties directly on an object, returning the object.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Syntax

Object.defineProperties(obj, props)

Parameters

obj

The object on which to define or modify properties.

props

An object whose own enumerable properties constitute descriptors for the properties to be defined or modified. Property descriptors present in objects come in two main flavors: data descriptors and accessor descriptors (see Object.defineProperty() for more details). Descriptors have the following keys:

configurable

true if and only if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.Defaults to false.

enumerable

true if and only if this property shows up during enumeration of the properties on the corresponding object.Defaults to false.

value

The value associated with the property. Can be any valid JavaScript value (number, object, function, etc).Defaults to undefined.

writable

true if and only if the value associated with the property may be changed with an assignment operator.Defaults to false.

get

A function which serves as a getter for the property, or undefined if there is no getter. The function's return value will be used as the value of the property.Defaults to undefined.

set

A function which serves as a setter for the property, or undefined if there is no setter. The function will receive as its only argument the new value being assigned to the property.Defaults to undefined.

Return value

The object that was passed to the function.

Description

Object.defineProperties, in essence, defines all properties corresponding to the enumerable own properties of props on the object obj object.

Example

Polyfill

Assuming a pristine execution environment with all names and properties referring to their initial values, Object.defineProperties is almost completely equivalent (note the comment in isCallable) to the following reimplementation in JavaScript: