angularjs – Angular和IE9愚蠢的原生方法

前端之家收集整理的这篇文章主要介绍了angularjs – Angular和IE9愚蠢的原生方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在Angular 1.2.0中,有一个有趣的评论

// IE stupidity! (IE doesn’t have apply for some native functions)

它位于functionCall函数的9835行:

functionCall: function(fn,contextGetter) {
    var argsFn = [];
    if (this.peekToken().text !== ')') {
      do {
        argsFn.push(this.expression());
      } while (this.expect(','));
    }
    this.consume(')');

    var parser = this;

    return function(scope,locals) {
      var args = [];
      var context = contextGetter ? contextGetter(scope,locals) : scope;

      for (var i = 0; i < argsFn.length; i++) {
        args.push(argsFn[i](scope,locals));
      }
      var fnPtr = fn(scope,locals,context) || noop;

      ensureSafeObject(context,parser.text);
      ensureSafeObject(fnPtr,parser.text);

      // IE stupidity! (IE doesn't have apply for some native functions)
      var v = fnPtr.apply
            ? fnPtr.apply(context,args)
            : fnPtr(args[0],args[1],args[2],args[3],args[4]);

      return ensureSafeObject(v,parser.text);
    };
  },

我相信这会让我感到痛苦,但是没有错误被抛出,所以我很难看到它可能正在尝试(并且失败)调用apply的本机功能.自从我实现了$q库以使用promises来处理异步REST调用之后,IE9甚至没有尝试调用服务(根据开发工具中的网络选项卡).相反,承诺立即被拒绝.我试着谷歌搜索答案,并看着角度的docs on using IE,但我无处可去.

有没有人有类似的问题,使用angular的“q-lite”获得使用IE9工作的承诺?有谁知道这个愚蠢的评论具体指的是什么?

解决方法

我相信我通过大量的反复试验弄明白了.在我的例子中,问题似乎是我使用内置的q库进行承诺…特别是q.all([]):

$q.all([
  firstRequest.$promise,secondRequest.$promise,thirdRequest.$promise,moreRequets.$promise
]).then(function() {
  //do stuff
});

虽然我还没有找到角度代码在说出一些原生函数时所指的具体操作,但我发现docs for function.apply()有以下警告:

Note: Most browsers,including Chrome 14 and Internet Explorer 9,still do not accept array-like objects and will throw an exception.

无论具体细节如何,删除我对$q.all的引用都为我解决了这个问题.我希望这有助于将来遇到此问题的任何人.如果有人碰巧遇到另一种情况,这种IE行为会使角色变得尖锐,也许他们会非常友好地在下面评论添加答案.

仅供参考,我目前处于角度1.2.14.

猜你在找的Angularjs相关文章