5
在我的haxe项目中,我的目标是使用javascript,并且使用@:expose
来暴露类,以便从外部haxe项目中调用它。在Firefox中看不到的静态属性
在我的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");
}
}
下面是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>
这里是汇编的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
如果您在编译的js和源代码(或者是重现此问题的简化版本)中粘贴,那么可能有人可以帮助您进行调试。没有语境,就不可能知道为什么有什么东西被打破。 – Chii