Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
}
like image 857
rener172846 Avatar asked Nov 21 '17 03:11

rener172846


2 Answers

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.

like image 131
Andy Li Avatar answered Oct 05 '22 20:10

Andy Li


var newConfig = Reflect.copy(config)
like image 34
KevinResoL Avatar answered Oct 05 '22 20:10

KevinResoL