我需要将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