[Javascript] Object.assign()
Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html
Object.assign() can extend the object by adding new props:
let obj = { first_name: 'Zhentian', age: 27 } Object.assign(obj, {last_name: 'Wan'}); console.log(obj);
log out:
let obj = { first_name: 'Zhentian', age: 27 } Object.assign(obj, {last_name: 'Wan'}); console.log(obj);
You can also assign multi props:
Object.assign(obj, {last_name: 'Wan'}, {location: 'Shanghai'});
SO it will logout:
[object Object] { age: 27, first_name: "Zhentian", last_name: "Wan", location: "Shanghai" }