[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"
}

 

posted @ 2015-11-12 03:13  Zhentiw  阅读(614)  评论(0编辑  收藏  举报