this: The Four Binding Rules
Learn this: The Four Binding Rules (Phase 4 · Scope, Hoisting, Closures, this (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
What is this? • this is decided by how a function is called , not where it is written (except for arrow functions). • Method call obj.fn() : this is obj . Plain call fn() : this is undefined in strict mode (the global object otherwise). • Constructor call new Fn() : this is the new object. • Explicit: fn.call(obj, a) , fn.apply(obj, [a]) , fn.bind(obj) set this directly.