Comparison
Prototype chainvsthis binding
Prototype chain
the object did not have the method but calling it worked anyway, because something further up did.
The chain of objects a property lookup walks when the property is not found directly, ending at `null`. It is the mechanism `class` is built on, and the reason `Object.keys` and a `for...in` loop disagree about what an object contains. It matters most when it bites: an object used as a dictionary inherits `toString` and friends, which is why `Object.create(null)` and `Map` exist.
Full entry →this binding
you passed the method as a callback and it lost the object it belonged to.
The rule that in a normal function `this` is decided by how the function is called, not where it was written. Extracting a method and passing it as a handler drops the receiver, which is why class methods get bound in the constructor or written as arrow functions. Arrow functions have no `this` of their own and take it from the enclosing scope, which is what makes them the default inside components.
Full entry →