把两个对象的属性合并一起, 这里form.age值被更新为15
let form = {name: 'liming', sex: '男' ,age: 16};
let obj = {class: '一班', age: 15};
console.log('before', form);
Object.assign(form, obj);
console.log('after', form);
image.png
Object.assign(this.dataForm, newObj); //this.dataForm被修改
let newObj_=Object.assign({},this.dataForm, newObj); //this.dataForm不会被修改
--by Affandi ⊙▽⊙
网友评论