I have a problem with TypeScript replacing $(this) with $(_this) and breaking the code, because test refers to window.
$(".class").click(() => {
var test = $(this);
console.log(test);
});
compiles to
$(".class").click(function () {
var test = $(_this);
console.log(test);
});
If you don't want to capture the lexical this, don't use an arrow function. Just use a regular function expression:
$(".class").click(function () {
var test = $(this);
console.log(test);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With