Haxe compiler metadata can be really handy to get specific behavior or to tweak the language based on your needs.
You can get the full list of supported compiler flags by running haxe --help-metas
.
It’s a big list and the following are some of my favourites.
@:overload
- I use this a lot when writing externs where you can overload fucntion paramater declarations and return type. The first one that is matched will be used.
@:final
- When you want to mark the class as final.
If you try to extend MyClass
you will get compile time error Cannot extend a final class
.
@:optional
- When you want to declare optional fields in typedef
.
@:publicFields
- When you want to change the default visibility of the whole class and it’s sub classes from private
to public
. I find this useful for static classes.
@:keep
- Unused variables and functions will be removed with dead code elimination -dce full
. You can force to keep them using this metadata.
All of the above are generic metadata and can be used across platforms and there are many more generic and platform specific metadata you may find useful for your specific needs so explore and please post in the comments section if you find anything interesting.
Update (14 Jan 2015): Another JavaScript specific metadata which I find useful is @:expose
. It can be used on any class to make it available/accessible from the window object. This is useful when you want to expose any of your haxe classes to another library via window object.