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
Post a Comment