I have some struggle to understand how the arrow functions in JS actually work.
Please consider this snippet
editButton.onclick = () => this.edit(input);
edit(input){
input.disabled = !input.disabled;
}
Why does that work but this here not?
editButton.onclick = function() {
this.edit(input);
}
}
edit(input){
input.disabled = !input.disabled;
}
Not the same? If I replace this.edit(input)
with console.log("Test");
it works on both but this.edit(input)
somehow not, why is that so?
I mean () =>
is basically function() { }
no??