使用Object.assgin(ObjToExpand, ObjWithNewData)

  var obj1 = {
        a:1,
        b:2
    };
    var obj2 = {
        c:3,
        d:4
    };
    Object.assign(obj1,obj2);
    console.log('obj1',obj1); //{a: 1, b: 2, c: 3, d: 4}
    console.log('obj2',obj2); //{c: 3, d: 4}

MDN上的解释

标签: none 阅读量: 1350

添加新评论