javascript - How do you merge two objects with functions into a new one using ES6? -
i want join 2 objects functions merged object using es6, not sure how this.
for example, i'd merge these 2 objects:
const first = {   first: function() {     return {       type: first     };   } };  const second = {   second: function() {     return {       type: second     };   } }; into new object:
const new = {   first: function() {     return {       type: first     };   },   second: function() {       return {       type: second     };   } } what best way this?  tried object.assign({}, first, second); returned {}.
any appreciated!
you should able use object.assign this:
note mentioned in chris' answer below, mutate first object.
var joined = object.assign(first, second);  // joined:  {   first: function first() {     return {       type: first     };   },   second: function second() {     return {       type: second     };   } } 
Comments
Post a Comment