Chapter XXI · The `this` Keyword
Explicit Binding
Explicit binding allows developers to manually assign a specific `this` context using `call`, `apply`, or `bind`.
01 How It Works
Think of handing a specific ID badge directly to a worker before they step onto the floor.
Methods like `call` and `apply` invoke functions immediately with a forced `this` target, while `bind` returns a permanently locked wrapper function.
example.js
function greet() {
console.log(this.name);
}
const user = { name: "Alice" };
greet.call(user); // "Alice"
1. Target a function with an ambiguous `this` context.
2. Use `.call()`, `.apply()`, or `.bind()` to supply an explicit object.
3. Execute function with guaranteed context binding.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
function show() { console.log(this.id); }
show.call({ id: 99 });
Key Takeaway
Explicit binding lets you manually control and override what `this` points to.