function associate( obj1 ,obj2 , key ){
if(typeof key === 'object'){
for ( var i in key )
associate(obj1, obj2 , key[i]);
} else {
obj1.watch(key, function (id, oldval, newval) {
obj2[id] = newval;
return newval;
});
}
}
I wrote this function because if have to different obj and both need to be updated. What do you think about this function?
obj = { key1: 'value2', key2: 'value2'}
obj2 = {key1: 'value2', key2 : 'value2'}
associate( obj ,obj2 , 'key1' )
obj.key1 = 'new value';
console.log(obj.key1)
--> 'new value'
console.log(obj2.key1)
--> 'new value'