JavaScript Edu Resources. Angular Courses. React Tutorials. Join us!

Haxe: working with JavaScript libraries

  • From Haxe, just call your exposed functions thanks to the “untyped” keyword:

    Although I’d generally recommend method 1., it’s fun to know the funky things you can do in Haxe so I’ll show you anyway 😉

    Maybe you don’t want a side JS, or maybe you really prefer the code to happen on the Haxe side but you don’t have good quality “externs” (see 3.)

  • This isn’t a new concept if you think about it: C++ header files, old ActionScript 2 “intrinsics”, and Haxe “externs” serve the same role: telling the compiler that a number of types you want to use will be “available” when your code will run.
  • Once you have such extern (it looks like an interface) in your classpath, the Haxe compiler will let you naturally manipulate external JS code, providing excellent inference and compile-time errors.
  • I won’t recommend you to jump right away on creating externs for a big JS library out there, especially if you aren’t an experienced and motivated Haxe developer: creating and keeping up to date such definitions require dedication; there is nothing more frustrating that discovering out of date (or incorrect) ones.
  • Haxelib is Haxe’s package manager (think npm or bower) and using it is very simple:

    However it happens that the externs aren’t super up to date.



Haxe: working with JavaScript libraries

Comments are closed, but trackbacks and pingbacks are open.