2026前端面试题(四) 箭头函数没有自己的 this它会继承定义时外层作用域的 this且终生不变。特性普通函数箭头函数this来源调用时确定谁调用指向谁定义时捕获外层this能否被改变可以通过call/apply/bind改变不能始终绑定定义时的this作为构造函数可以new不可以严格模式影响严格模式下this可能为undefined不受影响对象字面量不构成独立作用域const obj { name: Alice, say: () { console.log(this.name); // this 指向定义时的上下文通常是 window/global } }; obj.say(); // undefined或全局的 name原因say 定义在对象字面量中但对象字面量不构成独立作用域外层是全局作用域。this 是不是按钮// ❌ 错误箭头函数导致 this 不是按钮 button.addEventListener(click, () { this.classList.add(active); // this 是外层作用域不是 button }); // ✅ 正确普通函数this 指向触发事件的元素 button.addEventListener(click, function() { this.classList.add(active); });什么时候该用箭头函数适合用不适合用需要保留外层this的回调如setTimeout、map、forEach需要动态this的对象方法简短的函数表达式需要作为构造函数链式调用中的回调需要arguments对象箭头函数没有function Timer() { this.seconds 0; // 箭头函数保留 Timer 实例的 this setInterval(() { this.seconds; console.log(this.seconds); }, 1000); } const t new Timer(); // 正常累加不会指向 window而是指向实例