Last active
December 29, 2015 14:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-js module1.js | |
-main modules.Module1 | |
--next | |
-js module2.js | |
modules.Module2 | |
-D module2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
</head> | |
<body> | |
<script src="module2.js"></script> | |
<script src="module1.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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