JS modern

Starting as an option in Haxe 2.09, and as default in Haxe 3, the JS output is modernized, meaning:

  • Output runs in ES5 strict mode, allowing for more robust and optimizable JS.
  • Output is wrapped in a (function() {})() to prevent writing to the global namespace, and allow JS minifiers to be more efficient. You can intentionally write classes and static methods to the global namespace by tagging them with @:expose:
    class MyExternalClass { }

    Where "someLib.SomeName" is the optional exposed location of the class or function. By default, @:expose uses the full class and package name for the exposed location.

Haxe 3+

  • Modern JS output mode is the default
  • Enable Classic JS mode with -D js-classic

Haxe 2.09+

  • Classic JS output remains the default
  • Enable Modern JS output mode with --js-modern
version #19728, modified 2013-09-02 17:21:16 by Danielku15