This is useful when you know you need many methods of a given class to be bound to the classes instance. Another way to do this is to selectively use instance properties:
class Test {
constructor(){
document.addEventListener('click',this.onClick);
}
onClick = e =>{
console.log('click',this);
}
otherMethod e =>{
console.log('test',this);
}
}
Avoiding classes is another way to not have to deal with this issue 😉
This one is bad enough that I feel the need to put a warning. This is some weird obfuscation… I’ve put labels before global variable definitions so they look like type declarations.
It’s funny, monaco says lots of stuff about this one if you hit the Try it out… button you can see…