Using ES6 arrow functions with lexical this
binding is great.
However, I ran into an issue a moment ago using it with a typical jQuery click binding:
class Game {
foo() {
self = this;
this._pads.on('click', function() {
if (self.go) { $(this).addClass('active'); }
});
}
}
Using an arrow function instead:
class Game {
foo() {
this._pads.on('click', () => {
if (this.go) { $(this).addClass('active'); }
});
}
}
And then $(this)
gets converted to ES5 (self = this) type closure.
Is a way to have Traceur ignore "$(this)" for lexical binding?