, , :
public static function zip(objects:Array):Object
{
var r:Object = {};
for each (var o:Object in objects)
for (var k:String in o)
r[k] = o[k];
return r;
}
:
var obj:Object = {
"foo": 1,
"bar": 2,
"baz": 3
};
var obj2:Object = {
"bar": 4,
"baz": 6
};
var obj3:Object = {
"foo": 3,
"bar": 6
};
var result:Object = zip([obj, obj2, obj3]);
for (var k:String in result)
trace("Property:", k, result[k]);
:
Property: foo 3
Property: baz 6
Property: bar 6
Side note. This is a lossy method because the resulting object does not know where the individual properties came from and only stores the latest version of the value. If you want to keep this information, then there is another way to do this using the prototype chain. These are, for example, how, for example, Flex frame style settings.
source
share