Skip to content

Instantly share code, notes, and snippets.

@sonygod
Forked from jasononeil/Module1.hx
Created November 19, 2013 12:04
Show Gist options
  • Select an option

  • Save sonygod/7544380 to your computer and use it in GitHub Desktop.

Select an option

Save sonygod/7544380 to your computer and use it in GitHub Desktop.
-main Module1
-js module1.js
--next
-main Module2
-js module2.js
--next
-D sharedcode
-js sharedcode.js
SharedCode
class Module1
{
static function main() {
SharedCode.greet("Jason");
}
}
class Module2
{
static function main() {
SharedCode.greet("Anna");
}
}

SharedCode.js

(function () { "use strict";
var SharedCode = function() { }
$hxExpose(SharedCode, "SharedCode");
SharedCode.greet = function(name) {
	console.log(name);
}
function $hxExpose(src, path) {
	var o = typeof window != "undefined" ? window : exports;
	var parts = path.split(".");
	for(var ii = 0; ii < parts.length-1; ++ii) {
		var p = parts[ii];
		if(typeof o[p] == "undefined") o[p] = {};
		o = o[p];
	}
	o[parts[parts.length-1]] = src;
}
})();

Module1.js

(function () { "use strict";
var Module1 = function() { }
Module1.main = function() {
	SharedCode.greet("Jason");
}
Module1.main();
})();

Module2.js

(function () { "use strict";
var Module2 = function() { }
Module2.main = function() {
	SharedCode.greet("Anna");
}
Module2.main();
})();
#if sharedcode
@:expose // Make sure this code is available to other JS files
#else
extern // Make sure this code isn't compiled otherwise
#end
class SharedCode
{
static function greet(name:String):Void {
trace (name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment