我是ES6的新手,并且无法完成这项工作:
$(this) 单击时返回undefined?
dom.videoLinks.click((e) => {
e.preventDefault();
console.log($(this));
var self = $(this),
url = self.attr(configuration.attribute);
eventHandlers.showVideo(url);
// Deactivate any active video thumbs
dom.videoLinks.filter('.video-selected').removeClass('video-selected');
// Activate selected video thumb
self.addClass('video-selected');
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变它所以不是像这样的箭头函数,它按预期工作?:
dom.videoLinks.click(function(e) {
e.preventDefault();
console.log(this);
console.log($(this));
var self = e.this,
url = self.attr(configuration.attribute);
eventHandlers.showVideo(url);
// Deactivate any active video thumbs
dom.videoLinks.filter('.video-selected').removeClass('video-selected');
// Activate selected video thumb
self.addClass('video-selected');
});
Run Code Online (Sandbox Code Playgroud)
那么如果我在回调中使用箭头函数,我该怎么做呢?