2026-09-14 · 6 min
this in JavaScript, without the mythology
In a function, this depends on the call site: obj.method() binds obj. Bare fn() is undefined in strict mode. call/apply/bind set it. new sets the instance. Arrows use lexical this from the enclosing scope.
const f = obj.method; f() loses this. Page objects that pass this.submit to addEventListener have the same bug. Bind, wrap in an arrow, or use a class field arrow.
You do not need to recite every edge. You do need to predict this in a callback you wrote yesterday.