我創建了以下NodeJs
模塊的NodeJS模塊上的 「不確定」:
import $ from 'jquery';
module.exports =() => {
$("#clients-table tbody tr").click(() => {
let $this = $(this);
console.log($this);
console.log($(this));
console.log($(this).attr("class"));
console.log($("#clients-table tbody tr").attr("class"));
console.log("end");
});
}
和我Browserify
入口點看起來是這樣的:
"use strict";
import $ from 'jquery';
import test from './test';
test();
當我點擊元素時,點擊事件被觸發,但$(this)
是undefined
。 這裏有不同的console.logs
結果:
test.js:9 he.fn.init {}
test.js:10 he.fn.init {}
test.js:11 undefined
test.js:12 test
test.js:13 end
任何想法,爲什麼?
[用ES6箭頭功能使用jQuery $(本)(詞法此綁定)的可能的複製(HTTP:// stackov erflow.com/q/27670401/218196) –