Haxe for javascript without global namespace pollution?

后端 未结 4 813
無奈伤痛
無奈伤痛 2021-02-06 04:54

This question only applies to Haxe version < 2.10

I\'ve known about haxe for a while, but never really played with it until yesterday. Being curious,

相关标签:
4条回答
  • 2021-02-06 05:03

    I use the namespace switch on the compiler to clean those global root types up.

    0 讨论(0)
  • 2021-02-06 05:04

    Haxe is not meant to be used for writing an isolated reusable component in a javascript web application. This is evidenced by the fact that the compiler emits standard library for every goddamn compilation. Most optimal use of javascript target is to write an application entirely in haxe and call external stuff using untyped blocks hoping it won't break anything. You should treat haxe output like a flash clip, oblivious to the environment it runs in, assumes it is the only thing running.

    Or you might try wrapping the code with a with() block.

    0 讨论(0)
  • 2021-02-06 05:14

    there's a namespaced (experimental) haxe compiler here http://github.com/webr3/haxe

    0 讨论(0)
  • 2021-02-06 05:14

    The JSTM JavaScript generator macro optimizes haxe output in a number of ways:

    1. the javascript output is split into seperate files per type
    2. these files are optimized
    3. a loader script loads the required types asynchronously
    4. only one global variable is used: jstm
    5. only code that is actually required to run your app is downloaded
    6. new types can be loaded at runtime which makes possible highly scalable apps

    check out http://code.google.com/p/jstm/ for more info.

    0 讨论(0)
提交回复
热议问题