score:1

Accepted answer

That's because of how scope and functions work in javascript. If you change your function to an arrow function it will automatically bind the scope and you will see what you expect.

As a quick explanation: Arrow functions autobind the scope where they are declared while functions don't so you have to explicitly bind the scope you want to the function.


Related Query

More Query from same tag