rener172846
rener172846

Reputation: 451

How to clone Dynamic object in Haxe?

I have a Dynamic object from Json and need to clone that in Haxe. Is there any easy way to clone object, please let me know. Or if it's impossible, I want at least iterate that Dynamic object such as JavaScript object.

var config = {
    loop : true,
    autoplay : true,
    path : "data.txt"
};
var newConfig = {};
for (i in config) {
    if (config.hasOwnProperty(i))
        newConfig[i] = config[i];
}

Upvotes: 7

Views: 2291

Answers (2)

Andy Li
Andy Li

Reputation: 6034

Use Reflect.copy():

var newConfig = Reflect.copy(config);

Note that it only guaranteed to work on anonymous structures. For other objects, use the appropriate Reflect methods.

Upvotes: 10

KevinResoL
KevinResoL

Reputation: 982

var newConfig = Reflect.copy(config)

Upvotes: 2

Related Questions