This content originally appeared on DEV Community and was authored by ZhiHong Chua
1. Understanding this
, apply
, call
, and bind
with ChatGPT.
So I told GPT I was unsure of these concepts and made it test me with some questions then evaluate my answers. Here are my takeaways.
-
call
uses comma-separated arguments, andapply
uses array of arguments -
this
refers to (1) object itself in object methods, (2) newly created instance in constructor methods, and (3) global object (window) in global function non-strict mode - arrow functions inherit
this
from lexical context, while traditional functions inheritthis
from where it is called -
bind()
helps us attach a context to a function that will be used later
More questioning:
-
global
mode is not preferred these days, but may be encountered when dealing with legacy code
const user = {
name: 'Bob',
greet: function() {
// Regular function in setTimeout: `this` is not bound to `user`.
setTimeout(function() {
console.log('Regular timer:', this.name);
}, 1000);
// Arrow function in setTimeout: inherits `this` from greet.
setTimeout(() => {
console.log('Arrow timer:', this.name);
}, 1000);
}
};
user.greet();
// Expected Output after 1 second:
// "Regular timer:" may log undefined (or error in strict mode).
// "Arrow timer: Bob" logs correctly.
This content originally appeared on DEV Community and was authored by ZhiHong Chua

ZhiHong Chua | Sciencx (2025-02-10T05:01:39+00:00) Frontend Fundamentals 11 (Wtf is `this`?). Retrieved from https://www.scien.cx/2025/02/10/frontend-fundamentals-11-wtf-is-this/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.