JavaScript this Tutorial: Calls, Receivers, and Lexical Capture
For ordinary functions, this depends on invocation rules rather than simply where the function is stored. Extracting a method can therefore change behavior. Arrow functions follow lexical this instead, so distinguish the function form and call expression before predicting which object a property access will use.
Here's a popular JavaScript this video — watch it, then summarize it with one click. Or paste any other YouTube link below.
— or paste your own YouTube link —
Want to keep the key points from a YouTube video? Paste the link below to turn it into structured notes.
Why Use JavaScript this Tutorial: Calls, Receivers, and Lexical Capture
- Read the actual call expression
- Distinguish receiver from lexical scope
- Track extracted methods
- Apply explicit binding deliberately
- Recognize arrow-function differences
Frequently Asked Questions
Does naming a function as an object's property permanently bind it?
A property can hold a function reference without fixing every later call's receiver. Calling that reference separately can follow different this rules from invoking it through the original object's property access.
Is this identical to the surrounding lexical variables?
Ordinary this selection and lexical variable lookup are separate mechanisms. Explain each according to its rules instead of assuming access to an outer binding means the same object becomes the invocation receiver.
What does binding an ordinary function create?
It creates a callable with the supported bound receiver and arguments behavior. Understand that new function's contract rather than expecting the original function object or every unrelated reference to be rewritten automatically.
Why can an arrow callback retain a surrounding this?
Arrow functions use lexical this from their creation context rather than ordinary dynamic selection. That can suit callbacks, but it does not make every arrow placed inside an object behave like a receiver-dependent method.
Should debugging this begin with a class or variable name?
Begin with the function form and actual invocation that produced the value. Familiar names and file locations do not establish a receiver when the callback was passed or extracted through another execution path.