Static Property Not Visible in Firefox

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 { /* Using this var results in undefined example at Firefox console: >> com.Main.instance undefined */ @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'); } /* Calling this method results in error example at Firefox console: >> com.Main.instance.init(); TypeError: com.Main.instance is undefined */ 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); //# sourceMappingURL=map.js.map 
+5
source share
1 answer

Using the Haxe properties from external JS code is actually not supported as far as I know (see question # 2469 ).

You can directly call the getter (e.g. com.Main.get_instance().init() ) or check this problem for other solutions.


Note. I can’t confirm that the example works in Chrome (59 or 60), and really, I don’t think it could.

+1
source

Source: https://habr.com/ru/post/1269447/


All Articles