liveBook · Manning

Object.defineProperty

Object.defineProperty is a JavaScript built-in method that creates or modifies an object property using an explicitly specified property descriptor.

How 3 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

A JavaScript method that defines or modifies a property on an object with explicit control over its attributes.

How it is used
Configures property attributes for enumeration and prototype repair, or defines accessors that respond to property reads and writes.
How deep it goes
Works through descriptor attributes, a constructor-property repair, and a getter/setter implementation rather than merely naming the API.
Examples
Uses a nonenumerable `sneaky` property, a restored prototype `constructor`, and a `skillLevel` property backed by getter and setter functions.
What you can do after
Apply it via Object.defineProperty to control enumeration, restore a prototype’s constructor property, or define getter and setter behavior.

Read how Secrets of the JavaScript Ninja, Second Edition explains Object.defineProperty →

Secrets of the JavaScript Ninja, Third Edition

Object.defineProperty is a JavaScript built-in method that creates or modifies an object's property with a specified property descriptor.

How it is used
Adds properties dynamically or controls their behavior through descriptors, especially when defining accessors on existing objects.
How deep it goes
Explains accessor and data-property descriptors through examples of enumeration, assignment, and deletion behavior.
Examples
Uses a ninjaCollection accessor, a random-number getter, a password-hashing setter, property deletion, and a value property.
What you can do after
Apply it to add accessors or data properties and control their enumeration, writability, or configurability.

Read how Secrets of the JavaScript Ninja, Third Edition explains Object.defineProperty →

JavaScript in Depth

A JavaScript standard library method that defines or redefines a property with explicit descriptor attributes.

How it is used
Controls property mutability, enumeration, deletion, redefinition, and accessor behavior through explicit descriptors.
How deep it goes
Explains descriptor flags, default differences, strictness effects, and accessor descriptors, stopping short of broader runtime internals.
Examples
Uses drawer contents, internal identifiers, serial numbers, object-literal defaults, and getter-setter properties.
What you can do after
Apply it via Object.defineProperty() to create controlled data or accessor properties and predict assignment, iteration, and deletion outcomes.

Read how JavaScript in Depth explains Object.defineProperty →

Also covered in

What to know first

Related concepts

Questions about Object.defineProperty

What is Object.defineProperty?

Object.defineProperty is a JavaScript built-in method that creates or modifies an object property using an explicitly specified property descriptor.

Which Manning books explain Object.defineProperty?

Secrets of the JavaScript Ninja, Second Edition, Secrets of the JavaScript Ninja, Third Edition and JavaScript in Depth.

What should I know before learning Object.defineProperty?

Manning books that teach Object.defineProperty usually introduce for...in, object literal, attribute and class first.

What is the difference between Object.defineProperty and Object.assign?

Object.defineProperty is a JavaScript built-in method that creates or modifies an object property using an explicitly specified property descriptor. Object.assign is a JavaScript static method that copies enumerable own properties from source objects to a target object and returns the target.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.