Is there a built in function two compare two objects and give me a difference object? I'm also hoping to use that resulting object with differences and apply it to an object. Are there built in ways to do that in actionscript or do I roll my own function like this https://stackoverflow.com/a/1200865/37759
Asked
Active
Viewed 124 times
1 Answers
0
There isn't build-in way to do this, only own function.
I suggest this 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

fsbmain
- 5,267
- 2
- 16
- 23