Actionscript - get difference between two objects -


is there built in function 2 compare 2 objects , give me difference object? i'm hoping use resulting object differences , apply object. there built in ways in actionscript or roll own function https://stackoverflow.com/a/1200865/37759

there isn't build-in way this, own function.

i suggest code:

public static function diff(obj1:object, obj2:object):object {     if(!obj1 || !obj2)         return null;      var diffobj:object = {};     for(var key:string in obj1)     {         if(key in obj2)         {             diffobj[key] = obj1[key] - obj2[key];         }     }      return diffobj; }  diff({prop1:1, prop2:2}, {prop2:2, prop1:3})  //output: [object object]:     prop2:int = 0     prop1:int = -2 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -