【发布时间】:2017-08-23 10:41:37
【问题描述】:
只是玩了一下JS,我想知道为什么下面的代码输出"foo"而不是"bar":
String.prototype.toLowerCase.bind("FOO").call("BAR")
据我了解,.bind("FOO") 返回一个函数,该函数将具有this 的"FOO",因此调用.bind("FOO")() 输出"foo"。
但是,.call("BAR") 用"BAR" 为this 调用函数,所以应该已经输出了"bar"。
我哪里错了?
【问题讨论】:
-
String.prototype.toLowerCase.bind("FOO")返回带有参数“FOO”的函数toLowerCase,如果您执行String.prototype.toLowerCase.bind("FOO")()或String.prototype.toLowerCase.bind("FOO").call(),您将得到foo作为输出。
标签: javascript function call bind