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

**URL:** <https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565>\
**Category:** Haxe\
**Tags:** haxe-js, extern, anon-structure\
**Created:** [April 4, 2018, 2:54pm UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565 "2018-04-04T14:54:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)\
**Post date:** [April 4, 2018, 2:54pm UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/1 "2018-04-04T14:54:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bubar](https://community.haxe.org/user_avatar/community.haxe.org/bubar/32/176_2.png) [@bubar](https://community.haxe.org/u/bubar)\
**Post date:** [April 4, 2018, 4:37pm UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/2 "2018-04-04T16:37:49Z")

</div>

I would use Reflection to do this

> **[Try Haxe !](https://try.haxe.org/#9c64c)**

---

<div class="post-metadata">

**Author:** ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)\
**Post date:** [April 5, 2018, 8:58am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/3 "2018-04-05T08:58:48Z")

</div>

`@:native` (on extern types) can help: [Try Haxe !](https://try.haxe.org/#EfB9D)

---

<div class="post-metadata">

**Author:** ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)\
**Post date:** [April 5, 2018, 9:44am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/4 "2018-04-05T09:44:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)\
**Post date:** [April 5, 2018, 9:45am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/5 "2018-04-05T09:45:46Z")

</div>

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}`

---

<div class="post-metadata">

**Author:** ![dmitryhryppa](https://community.haxe.org/user_avatar/community.haxe.org/dmitryhryppa/32/1815_2.png) [@dmitryhryppa](https://community.haxe.org/u/dmitryhryppa)\
**Post date:** [April 5, 2018, 10:08am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/6 "2018-04-05T10:08:12Z")

</div>

Is something like this will help?

> **[Try Haxe !](https://try.haxe.org/#4f8d9)**

---

<div class="post-metadata">

**Author:** ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)\
**Post date:** [April 5, 2018, 10:08am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/7 "2018-04-05T10:08:44Z")

</div>

Use double quotes for such fields: `{"default":true, "in": false}`

> **[Try Haxe !](https://try.haxe.org/#8e9Fe)**

---

<div class="post-metadata">

**Author:** ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)\
**Post date:** [April 5, 2018, 10:45am UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/8 "2018-04-05T10:45:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [April 5, 2018, 8:39pm UTC](https://community.haxe.org/t/how-objects-with-fields-which-are-haxe-keywords-should-be-defined/565/9 "2018-04-05T20:39:14Z")

</div>

FWIW, this [proposal](https://github.com/HaxeFoundation/haxe-evolution/pull/32), once implemented should address this nicely.
