Javascript 为什么可以';调用()函数。调用?

Javascript 为什么可以';调用()函数。调用?,javascript,call,Javascript,Call,在Javascript中,Function.call() 函数。调用本身就是一个函数。因此,理论上,Function.call应该与Function.call.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 R

在Javascript中,
Function.call()

函数。调用本身就是一个函数。因此,理论上,
Function.call
应该与
Function.call.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)
在V8中,情况似乎是这样的:

> Function.call === Function.call.call
true
当我们调用
Function.call()
时,我们得到一个匿名函数

> Function.call()
[Function: anonymous]
但是,我无法在
函数.call上调用
.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.call()
TypeError:undefined不是函数
回复:1:21
在REPLServer.defaultEval(repl.js:132:27)
绑定时(domain.js:291:14)
在REPLServer.runBound[as eval](domain.js:304:12)
在服务器上。(回复js:279:12)
在REPLServer.emit上(events.js:107:17)
在REPLServer.Interface.\u在线(readline.js:214:10)
在REPLServer.Interface._行(readline.js:553:8)
在REPLServer.Interface.\u ttyWrite(readline.js:830:14)
在ReadStream.onkeypress(readline.js:109:10)


这是怎么回事<代码>函数。调用
显然是一个函数-它并非如此错误消息所示的未定义。

简短回答:错误消息非常误导。这与您执行此操作时收到的错误消息相同

(undefined)();

更长的回答:

第二个
.call()
正在使用
函数的
this
调用

不带参数调用它会导致它调用
this
,并将
未定义的
作为
this

因此,你真的在做什么

Function.call.call(undefined)
undefined.call()
这意味着你(隐喻地)在做

这真的很公平

undefined()
不向
函数.call.call()
this
参数传递任何内容(或
未定义的
,实质上是否定第一个
函数.call()
this
上下文(这将只是
函数本身),导致
未定义的
调用
.call()


这会产生错误消息:
undefined不是一个函数

很好的问题和答案,即使在正常的编程环境中毫无意义:)@nicovank当然,但我在探索Javascript的一些“假设”时意外地遇到了这个问题。:@Bergi如果您传入一个
这个
值,请确定。混淆源于错误消息……因此工作示例是
Function.call.call(Function)
Function.call.call(console.log,console,“hello”)
@Bergi Correct。再一次,混乱源于错误信息。啊,我不知道你自己回答了你的问题。我只是觉得添加一个使用double-
call
的示例可能会有助于解释。