Skip to main content

WTF is `this` in JavaScript?


It’s the calling context, which depends on where and how it’s called.

new constructs this from a constructor, otherwise it’s the calling context. Rather than this being isolated to the function block, it takes the this from where the function is called. So if it’s at the top level, it inherits the global context, that’s why constructor functions panic without new.

You can specify a custom this with apply and call and the respective Reflect functions.


Thanks for reading! If you’ve enjoyed this post, you can support me by

Previous Page on AGCKB: