Why 'this' Uses Dynamic Binding
You'll learn: Why JavaScript's designers chose dynamic binding for this and how this decision enables flexible, reusable object-oriented patterns.
The Design Decision
JavaScript's this uses dynamic binding (determined at call-time) rather than lexical binding (determined at write-time) because of a deliberate design choice: flexibility over predictability. The language prioritizes patterns where methods can be shared, borrowed, and reused across different objects without rewriting code.
Enabling Object-Oriented Flexibility
Dynamic binding allows one function to serve multiple objects:
function describe() {
return `${this.name} is ${this.age} years old`;
}
const person1 = { name: "Alice", age: 30 };
const person2 = { name: "Bob", age: 25 };
// Same function, different contexts
console.log(describe.call(person1)); // "Alice is 30 years old"
console.log(describe.call(person2)); // "Bob is 25 years old"
If this were lexically bound, you'd need a separate function for each object. Dynamic binding lets you write generic, reusable methods.
Borrowing Methods
Dynamic binding makes method borrowing natural:
const calculator = {
value: 10,
add(n) { return this.value + n; }
};
const differentObject = { value: 50 };
// Borrow calculator's method
console.log(calculator.add.call(differentObject, 5)); // 55
The Trade-off
The cost? this can be confusing because context changes based on how you call a function, not where you write it. But this trade-off enables the flexible, prototype-based inheritance and method sharing that defines JavaScript's object model.
Key Takeaway: Dynamic binding of this sacrifices predictability for flexibility, allowing one function to operate on many different objects and enabling JavaScript's prototype-based, reusable patterns.