[haXe] dynamic object instantiation
Nicolas Cannasse
ncannasse at motion-twin.com
Fri Apr 28 18:17:35 CEST 2006
> I'm new to this list, and am excited to see what kind of activity is
> happening in the Haxe community. I've got a question for yall.
>
> A technique I'm used to using in Javascript is to get a class
> reference through eval then instantiating it. As I do not yet
> understand the typing very well in Haxe yet, I'd like to know the
> best way to do this. Here's how I would do it in javascript.
You should use the "Reflect" class, and in particular the
"createInstance" method :
var obj = Reflect.createInstance(js.Lib.eval("MyClass"),[arg1,arg2]);
Please note that it's not haXe philosophy to instanciate classes this
way, since you loose all the typing when using Reflect or "eval".
Nicolas
More information about the Haxe
mailing list