在Javascript中,Function.call()可以调用给定的Function值和零或多个参数。
Function.call本身就是一个函数。因此,从理论上讲,Function.call应该是与Function.call.call相同的(或类似的)函数。
在V8中,情况似乎是这样:
> Function.call === Function.call.call
true当我们调用Function.call()时,我们得到一个匿名函数
> Function.call()
[Function: anonymous]但是,我不能在.call()上调用Function.call。
> Function.call.call()
TypeError: undefined is not a function
at repl:1:21
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:291:14)
at REPLServer.runBound [as eval] (domain.js:304:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
at ReadStream.onkeypress (readline.js:109:10)这里发生了什么?Function.call显然是一个函数--它不是undefined,这条错误消息表明。
发布于 2016-11-30 09:40:08
简短的回答:错误信息非常误导。这是相同的错误消息,当您这样做。
(undefined)();更长的答案:
第二个.call()是用this of Function.call调用的。
不使用参数调用它将导致它以this作为this值调用this。
所以,你真的在做
Function.call.call(undefined)这意味着你在(隐喻地)做
undefined.call()这真的是
undefined()将任何东西(或undefined)传递给Function.call.call()的this参数本质上是否定了第一个Function.call()的this上下文(这将只是Function本身),从而导致在undefined上调用.call()。
这将产生产生的错误消息:undefined is not a function。
https://stackoverflow.com/questions/40884839
复制相似问题