Last active
February 7, 2021 06:43
-
-
Save nadako/5913724 to your computer and use it in GitHub Desktop.
A small hack to make JS global variable easily available in Haxe
This file contains 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
extern class Globals | |
{ | |
public static var context(get, never):Context; | |
inline static function get_context():Context return untyped __js__("context"); | |
} | |
extern class Context | |
{ | |
public function doStuff():Void; | |
} |
This file contains 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
import Globals.*; | |
class Main | |
{ | |
function someMethod() | |
{ | |
context.doStuff(); | |
} | |
} |
This file contains 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
var Main = function() { } | |
Main.prototype = { | |
someMethod: function() { | |
context.doStuff(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment