r/learnjavascript • • Mar 30 '26

question about `this.`

i understand that `this` refers to the caller of the function so how can `name` in `function Person(name){this.name = name;}` be assigned to `Person` since no object is calling

(this wasn't explained in that comment )

10 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/Umustbecrazy Apr 02 '26

In Event handlers , using regular functions as callbacks (non arrow), 'this' will be the element calling the event, so it's not always undefined as a callback. The exception I'm sure you are aware of.

1

u/azhder Apr 02 '26

Best not discuss exceptions like that, but the general rule that with .call() and .apply() you can specify what the this is and say that’s going on with Event handlers under the hood