参考不起作用

时间:2017-01-15 16:38:42

标签: javascript angularjs promise

我需要将i的引用传递给.then回调

var promises = loadScript(assets["js"][0]);
  for (var i = 1; i < assets["js"].length; i++){
    promises = promises.then(function() { loadScript(assets["js"][i]) });
  }

我试过了:

var promises = loadScript(assets["js"][0]);
  for (var i = 1; i < assets["js"].length; i++){
    promises = promises.then((function(i){loadScript(assets["js"][i])})(i));
  }

此处函数在.then方法调用

之前执行

从当时返回

var promises = loadScript(assets["js"][0]);
  for (var i = 1; i < assets["js"].length; i++){
    promises = promises.then( function() { return loadScript(assets["js"][i]) });
  }

我收到错误:

i = undefined

0 个答案:

没有答案