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.lo开发者_如何学运维g(obj.key1) 
  --> 'new value'
  console.log(obj2.key1) 
  --> 'new value'
It won't work. At all.
return obj1[id] = obj2[id] = newval;
That in particular isn't going to get you anywhere.
Feel free to use http://www.jslint.com/ should you want to find issues in your code.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论