[haXe] dynamic object instantiation
Joshua Kifer
joshua at rothbard.net
Fri Apr 28 18:05:35 CEST 2006
Hi all,
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.
var cls = eval('SomeClass');
var obj = cls(arg);
Here's my current Haxe hack to get this to work:
var obj = eval('new SomeClass()');
However, I cannot pass arguments in the eval, as they seem to lose
scope by the time the actual eval is called, hence this doesn't work:
var arg = 'foo';
var obj = eval('new SomeClass(arg)');
Any suggestions on how I can do this so I can pass an arg to the
constructor?
Joshua
More information about the Haxe
mailing list