额。。。这函数有什么特别的么
发布于 4 年前 作者 reverland 2380 次浏览 来自 问答
> var a = Promise.resolve
undefined
> a(1)
TypeError: a is not a function
    at resolve (native)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:248:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:412:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
1 回复

没特别,只是这样调用并不是以对象的方法的方式调用,上下文丢了。 这样:

> var a = Promise.resolve
undefined
> a.call(Promise, 2)
Promise { 2 }
回到顶部