liveBook · Manning

Object.assign

Object.assign is a JavaScript static method that copies enumerable own properties from source objects to a target object and returns the target.

How 2 Manning books explain it

The Joy of JavaScript

Object.assign is a JavaScript built-in function that copies enumerable own properties from source objects to a target object.

How it is used
Composes configuration, API responses, shallow clones, and mixins by copying independent property bags into one object.
How deep it goes
Explains enumerability, ownership, precedence, shallow copying, and setter behavior, while stopping short of recursive cloning.
Examples
Uses configuration defaults, API-response merging, shallow cloning, non-enumerable properties, inherited properties, and mixin method conflicts.
What you can do after
Apply it to construct composed objects, merge defaults, create shallow clones, and predict conflicts between source properties.

Read how The Joy of JavaScript explains Object.assign →

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A JavaScript static method that copies the values of enumerable own properties from one or more source objects to a target object and returns that target object.

How it is used
Uses Object.assign to fill default options and extend objects with additional properties.
How deep it goes
Works through source order, target mutation, setters, and own enumerable properties without descending into specification algorithms.
Examples
Uses pizza-tracking map options, enhanced spaceships, a validating setter, and an array copied into an object.
What you can do after
Apply it via Object.assign to set defaults, extend objects, and choose whether the original object is mutated.

Read how Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond explains Object.assign →

Related concepts

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.