这个
一句话解释
`这个` 是 keyword 那个 refers 到 对象 那个 是 currently 执行 code — 它的 值 depends on 如何 函数 是 called.
用大白话说
this is a special keyword whose value depends on how the current function was called. It is not fixed — it changes based on the calling context.
In a regular function call, 这个 is undefined (strict mode) or the global object. In a method call (obj.方法()), 这个 is obj. In a constructor call (新 Foo()), 这个 is the new instance. Arrow functions do not have their own 这个 — they inherit it from the enclosing scope.
You can explicitly set 这个 with call, apply, or bind. bind creates a new function with 这个 permanently fixed. This is useful for event handlers and callbacks where 这个 would otherwise be lost.
示例
const obj = {
name: "Ada",
greet() { return this.name; }
};
console.log(obj.greet()); // "Ada"
const fn = obj.greet;
console.log(fn()); // undefined — this is lost这个 是 obj 当 called as obj.greet(), 但 lost 当 extracted and called as fn().
常见混淆
容易混淆的对象: arrow 函数 这个
关键区别: Regular 函数 有 它们的 own 这个 determined 通过 call; arrow 函数 inherit 这个 从 enclosing lexical 作用域 and cannot 是 更改 使用 bind.
相关术语
相关资源
相关课程
- 对象
学习 关于 这个.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。