How can I merge two (or more) JS objects like this?
The result should contain all functions (like showUser and showOtherData) and events and requests-arrays should be merged as well.
var object1 = {
events: {
'app.activated': 'showUser'
},
requests: {
},
showUser: function() {
console.log("es jhsod")
},
};
var object2 = {
events: {
'app.destroyed': 'hideUser'
},
requests: {
main: {
url: 'http://example/api/main',
data: {
format: 'json'
}
}
},
showOtherData: function() {
console.log("foobar")
},
};