I don’t believe this is something that you can do without a macro. What is it that you are looking to do? If you just want to be able to access object fields at runtime, use the reflection API.
class Test {
static function main() {
trace("Haxe is great!");
var pairsOBJ = { "NAME":"value" };
var DATA:DataModal;
DATA = pairsOBJ;
trace(DATA.NAME);
}
}
typedef DataModal=
{
var NAME:String;
}
I know it’s outdated but found this looking for similiar problem.
Going JS way (and Dan’s suggestion) it could be sth like:
public static inline function NAME() { return "name"; }
static function main() {
var pairsOBJ:haxe.DynamicAccess<Dynamic> = {};
pairsOBJ.set(NAME(), "value");
trace(pairsOBJ[NAME()]);
trace(pairsOBJ.exists("name")); // true
}
Unfortunately it seems you can’t use (even static/derived/calculated) expression neither inlined function result directly as field identifier during object declaration [w/o macros] - it could be nice if possible.