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.

jsbin example

var joined = object.assign(first, second);  // joined:  {   first: function first() {     return {       type: first     };   },   second: function second() {     return {       type: second     };   } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -