[haXe] dynamic object instantiation
Joshua Kifer
joshua at rothbard.net
Fri Apr 28 18:25:50 CEST 2006
Perhaps some justification then. I'm working on a web framework that
needs to be able to discover assets at runtime, in this case,
javascript controller classes. I decided to go with haxe because it
takes care of class inheritance nicely, as well as the syntax
checking. I also decided to port my flash component over, so now can
compile the whole deal from a single script. Love the project!
Thanks for the tip.
On Apr 28, 2006, at 9:17 AM, Nicolas Cannasse wrote:
>> 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
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
More information about the Haxe
mailing list