this is decided by how a function is called, not where it is written. This is one of the most common sources of JavaScript bugs. Call style this is… obj.method() obj fn() (plain call) undefined in strict mode / modules (global object in sloppy mode) new Fn() the newly created object fn.call(ctx, a, b) / fn.apply(ctx, [a, b]) ctx fn.bind(ctx) returns a new function permanently bound to ctx Arrow function inherited from the surrounding scope (never its own) DOM event handler (function) the element the listener is attached to The classic bug Passing a method as a callback (setTimeout(obj.method)) detaches it from obj, so this is lost. Fix it with an arrow wrapper, bind, or a class field arrow function. Arrow functions are not methods Do not use arrows for object methods that need this…
Key Takeaways
this depends on the call site, not the definition.
Arrow functions inherit this lexically — great for callbacks, bad for methods.
bind returns a new permanently-bound function; call/apply invoke immediately.
Passing obj.method as a callback loses this — wrap it or bind it.