显式绑定中,null/undefined作为thisArg时:非严格模式下被替换为全局对象(window/global),严格模式下保持原值;箭头函数不受影响,bind返回函数同理。

在显式绑定(call、apply、bind)中,当传入的 thisArg 为 null 或 undefined 时,this 的实际绑定行为取决于是否处于严格模式。
非严格模式下 this 指向全局对象
在非严格模式中,JavaScript 会自动将 null 或 undefined 替换为全局对象:
- 浏览器环境 →
window - Node.js 环境 →
global - 该替换发生在调用前,属于引擎内部规范行为
严格模式下 this 保持原值
开启严格模式后,null 和 undefined 不再被转换,this 就是传入的原始值:
-
function() { 'use strict'; console.log(this); }.call(null)→ 输出null -
.call(undefined)→ 输出undefined - 这使得
this值更可预测,也更容易调试
箭头函数不受显式绑定影响
箭头函数没有自己的 this,它继承外层函数作用域的 this,因此无论用 call(null) 还是 bind(undefined) 都无法改变其 this:
-
const fn = () => console.log(this); fn.call({x:1})→ 仍输出外层的this - 这是语法层面的限制,与严格/非严格模式无关
bind 返回函数的 this 绑定也遵循相同规则
bind 创建的新函数,在后续调用时,其 this 行为和 call/apply 一致:
-
const bound = fn.bind(null); bound();→ 非严格模式下this是window -
'use strict'; const bound = fn.bind(undefined); bound();→this是undefined - 注意:
bind后再用call显式覆盖,新传入的thisArg仍受上述规则约束

















