Skip to content

Instantly share code, notes, and snippets.

@elsassph
Last active December 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsassph/21b92a2312fc24b1e39c to your computer and use it in GitHub Desktop.
Save elsassph/21b92a2312fc24b1e39c to your computer and use it in GitHub Desktop.
One approach to building Haxe JS modules - EDIT: see https://github.com/elsassph/modular-haxe-example
-js module1.js
-main modules.Module1
--next
-js module2.js
modules.Module2
-D module2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<script src="module2.js"></script>
<script src="module1.js"></script>
</body>
</html>
package modules;
class Module1
{
static public function main()
{
trace("Module1 is loaded");
var m1 = new Module1();
}
public function new()
{
trace("Module1 instance");
var m2 = new Module2();
}
}
package modules;
#if module2
// implementation only if compiled with -D module2
@:expose
class Module2
{
static function __init__()
{
trace("Module2 is loaded");
}
public function new()
{
trace("Module2 instance");
}
}
#else
// use the exposed class in other cases
@:native("window.modules.Module2")
extern class Module2
{
public function new();
}
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment