6.2.1 Native Metadata

When creating externs it is possible that certain fields will conflict with Haxe keywords, even though they are valid identifiers for the given target. These problems can be resolved by marking the conflicting fields with the metadata :native, with the intended identifier provided as a parameter.

extern class A {
  public function new();
  @:native("final") var final_:Int;
}

class Main {
  public static function main():Void {
    var a = new A();
    a.final_ = 3;
  }
}

The generated JavaScript output shows that we are actually assigning to the final field:

(function ($global) { "use strict";
var Test = function() { };
Test.main = function() {
    new A().final = 3;
};
Test.main();
})({});

This metadata can be applied to class and interface fields, but not the fields of a structure type.