← Todas las publicaciones
post17 de abril de 2026
¿A qué se refiere 'this'?
#javascript#this#binding#interview
How is 'this' determined in JavaScript? Explain the 4 binding rules.
'this' is set at call time by one of four rules (highest to lowest priority): 1. **new binding**: `new Foo()` → this = new empty object 2. **explicit binding**: `fn.call(obj)`, `fn.apply(obj)`, `fn.bind(obj)` → this = obj 3. **implicit binding**: `obj.fn()` → this = obj (the object before the dot) 4. **default binding**: `fn()` standalone → this = globalThis (or undefined in strict mode) ```js function greet() { console.log(this.name); } const josh = { name: 'Josh', greet }; josh.greet(); // 'Josh' (implicit) greet.call({ name: 'AI' }); // 'AI' (explicit) greet(); // undefined (default strict) ``` Arrow functions have no 'this' — they inherit from the enclosing lexical scope.