Example analysis of js Object.Assign method

This example tells the Object.Assign IM use of JS. Share to everyone for your reference, specifically:

Object.assign () is used to use the value of all enumerable home properties from one or Multiple source objects are copied to the target object. It will return the target object.

Object.assign (target, … Sourcees)

   Target: Target Object 
Sourcees: Any multiple source object

Return value

The return value is the target object after the merging properties, that is, Target.

Example 1 (attribute value is value type)

var obj1 = {a: 1}; var obj2 = {B : 2}; var Obj = {}; var o = Object.assign (Obj, obj1, obj2); console.log (o, obj);

operation results
   Example 2 (attribute value includes reference type) 

var obj1 = { A: 1, FN: function () {console.log (this);}}; var obj2 = {b: 2, c: {name: “bob”}}; var obj = object.assign ({} OBJ1, OBJ2); OBJ.FN (); // – >> 1console.log (obj.c.name); // – >> Bob js的Object.assign用法示例分析

Operation results :

 Increase global attributes to ReactNative Text components   
Import {text, textInput} from ‘React- native’TextInput.defaultProps = Object.assign ({}, TextInput.defaultProps, {defaultProps: false}); // use the new RN alternate method Text.defaultProps = Object.assign ({}, Text.defaultProps, {allowFontScaling: False});

Interested friends can use

online HTML / CSS / JavaScript code running tool js的Object.assign用法示例分析: http: //tools.jb51.net / code / htmljsrun test the above code running effect.

More about JavaScript related content, readers, interested, can view this topic: “JavaScript-oriented object-oriented tutorial”, “JavaScript error and debugging skill summary”, “JavaScript data structure and algorithm skill summary”, ” JavaScript Travel Algorithm and Skill Summary “and” Summary of JavaScript Mathematical Computing “

I hope this article will help you JavaScript programming.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment