COMMUNITY

How objects with fields which are haxe keywords should be defined?

anon-structure
haxe-js
extern

(Alexander Djafarov) #1

For instance how define such objects {default: true} or {in: true}?
Is it possible to give an alias for a typedef field?


(Fran├žois Barbut) #2

I would use Reflection to do this

https://try.haxe.org/#9c64c


(Rudy Ges) #3

@:native (on extern types) can help: https://try.haxe.org/#EfB9D


(Alexander Djafarov) #4

Thanks. But Dynamic is not very elegant solution. What if you need define the object {field1: Bool, field2: Bool,..., fieldN: Bool, default: Bool}?


(Alexander Djafarov) #5

Thanks for reply. But the code compiles to var o = new MyType(true,false);, but I need output like this var o = {default: true, in: false}


(Dmitry Hryppa) #6

Is something like this will help?

https://try.haxe.org/#4f8d9


(Aleksandr Kuzmenko) #7

Use double quotes for such fields: {"default":true, "in": false}
https://try.haxe.org/#8e9Fe


(Alexander Djafarov) #8

Yep, using of abstract can solve this issue. Thank you.


(Dan Korostelev) #9

FWIW, this proposal, once implemented should address this nicely.