<!doctype html><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><meta charset="UTF-8"/><title>Document</title></head><body> <script> var test=(function(a){ this.a=a; return function(b){ return this.a+b; } }(function(a,b){ return a; debugger; }(1,2))); console.log(test(4)) //结果是输出5 求解? </script></body></html>
1 回答

慕码人2483693
TA贡献1860条经验 获得超9个赞
记
let functionA = function (a) {
this.a = a
return function (b) {
return this.a + b
}
}
let argA = function (a, b) {
return a
debugger
}(1, 2)
// 实际上 argA 就等于 1,** 这个地方的 b 没有被用到 **
则原式简化成:
let test = functionA(argA)
此句执行完后 test
实为
function (b) {
return this.a + b
}
// ** 这是一个带一个参数的函数,执行 test(4) 时 b 就是 4 **
且此时 this.a
等于 1
。因此 test(4)
结果为 5
添加回答
举报
0/150
提交
取消