我是新的承诺,我不知道如何做到这一点。问题是我将拥有许多元素,对于每个元素,我将调用一个具有回调函数。当所有这些回调都被执行后,我想执行另一个函数。像这样:
var elements = [e1,e2, ...] //I don't know how many will be
for (var i = 0; i < elements.length; i++) {
functionWithCallBack(elements[i] ,function(){
//some magic
})
}
//When all the callbacks had been executed I want to execute this one
var finally = function(i){
//some code
}
我知道解决方案是有承诺的,但我无法做到这一点。任何建议?在此先感谢!!