在我的haxe项目中,我的目标是javascript,并使用@:expose来自外部haxe项目的类来公开类.
在我的Main班上,我instance用来访问单音班.
喜欢:
com.Main.instance
现在,当我尝试访问ini类中的函数时,它仅在使用Chrome时才有效,但在Firefox中会出错:
TypeError: com.Main.instance is undefined
知道为什么它在Chrome上运行,但在Firefox中却没有?
我使用的是haxe 3.4.0版
更新了 我添加最小化的haxe示例文件来重现问题
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");
}
}
Run Code Online (Sandbox Code Playgroud)
这是HTML页面:
<!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>
Run Code Online (Sandbox Code Playgroud)
这是编译的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
Run Code Online (Sandbox Code Playgroud)