javascript-Function.prototype.apply.apply-为什么要两次调用

今天,在检查Jasmine的源代码here时,我偶然发现了以下内容:

if (queueableFn.timeout) {
    timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
      var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
      onException(error);
      next();
    }, queueableFn.timeout()]]);
}

我对为什么在这里为什么两次调用apply感到很感兴趣.

解决方法:

commit that introduced this syntax解释了一切:

Older IE fixes Still not green, but getting close. Summary of Older
IE discrepancies:

  • Older IE doesn’t have apply/call on the timing functions
  • Older IE doesn’t allow applying falsy arguments
  • Older IE doesn’t allow setting onclick to undefined values
  • Older IE doesn’t have text property on dom nodes
上一篇:javascript-茉莉花:如何期望承诺处理程序不会引发异常


下一篇:javascript-量角器:如何获取当前浏览器的宽度?