In my haxe project, I target javascript and expose the class using @:expose to call it from an external haxe project.
In my Main class, I use instance to access a single tonality class.
like:
com.Main.instance
Now when I try to access the ini function inside the class, it will only work when using Chrome, but in Firefox it will get the error:
TypeError: com.Main.instance is undefined
Any idea why it worked in Chrome but not in Firefox?
I am using haxe version 3.4.0
Update I added a minimized haxe sample file to reproduce the problem.
package com; import js.Browser; @:expose class Main { @isVar public static var instance(get, null):Main = null; static function get_instance():Main { if (instance == null) instance = new Main(); return instance; } function new() { } static function main() { trace('Hello World'); } public function init(){ Browser.console.log("Main Initialized"); } }
Here is the HTML page:
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <script type="text/javascript" src="map.js"></script> </head> <body > <script> $(document).ready(function () { com.Main.instance.init(); }); </script> </body> </html>
And here is the compiled map.js:
// Generated by Haxe 3.4.0 (function ($hx_exports) { "use strict"; $hx_exports["com"] = $hx_exports["com"] || {}; var com_Main = $hx_exports["com"]["Main"] = function() { }; com_Main.get_instance = function() { if(com_Main.instance == null) { com_Main.instance = new com_Main(); } return com_Main.instance; }; com_Main.main = function() { console.log("Hello World"); }; com_Main.init = function() { window.console.log("Main Initialized"); }; com_Main.__meta__ = { statics : { instance : { isVar : null}}}; com_Main.main(); })(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this); //
source share