Object.assign() method

 

The Obejct.assign(target,source1,source2).
method is used for object merging, copying all enumerable properties of the source object (source) to the target object (target).

Notice:

1. This method only copies the own properties of the source object (does not copy inherited properties), nor does it copy non-enumerable properties ( enumerable: false)

2. This method is a shallow copy, which means that if an object of a reference type is merged, if the source object changes, the attribute value of the target object will also be changed accordingly.

3. The replacement of attributes with the same name requires special care.

4. There is an interesting array feature that can be used. Insert an array of source objects into the front of another array and delete the target array of the same length.

use:

1. Add properties to the prototype of an object, target: someClass.prototype, source: an object,

2. Add attributes to the object, so that the new instance object has the attributes of x and y on it. (constructor points to the object itself)

3. Clone objects and merge objects

4. Set default values ​​for properties

options = Object.assign({}, DEFAULTS, options);
 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324980523&siteId=291194637