我決定學習haxe來編譯JavaScript,我面對的問題是關於如何使用這種語言實現普通JavaScript的功能的信息和示例很少。也許有人可以幫助我理解我如何利用jQuery的每個功能,因爲它似乎不工作。它在編譯「js.html.Node沒有字段寬度」時給了我一個錯誤「Haxe和jQuery Extern函數庫的每個函數
這裏是代碼。
import js.Lib;
import js.Browser;
import jQuery.*;
class Main {
static private var _jqSlider:JQuery;
static public function main():Void {
new JQuery(function():Void { //when document is ready
myFunc();
});
}
static private function myFunc() {
_jqSlider = new JQuery("aSlider");
_jqSlider.children().each(function(i,ele) {
trace(ele.width());
});
}
}
謝謝。 我正在使用這些jQuery lib http://lib.haxe.org/p/jQueryExtern,我試過trace(JQuery.cur.width());給我的如下因素類沒有現場CUR,
static private function myFunc() {
_jqSlider = new JQuery("aSlider");
trace("hello"); // works fine as console.log("hello")
_jqSlider.children().each(function(i,ele) {
var ele = new JQuery(ele);
trace("hello"); // Action Ignored
trace(ele.width()); // Action Ignored
});
}'
這是它輸出的代碼爲JavaScript
(function (console) { "use strict";
var Main = function() { };
Main.main = function() {
$(function() {
Main.myFunc();
});
};
Main.myFunc = function() {
Main._jqSlider = $("aSlider");
console.log("hello");
Main._jqSlider.children().each(function(i,ele) {
var ele1 = $(ele);
console.log("hello");
console.log(ele1.width());
});
};
Main.main();
})(typeof console != "undefined" ? console : {log:function(){}});
你在使用什麼模塊加載器?你如何修改jQuery以符合ES6模塊? –