我正在尝试减少对多种功能的需求,尤其是因为许多功能都在promise做同样的事情。但是,我希望添加一个基于props父母的条件。例如我有一个功能example .doSomething() .then(something => { example.createSomething(something) });但是如何添加一个.doSomething()从propsofsomethingElse变为的条件.doSomethingElse()?因此,如果somethingElse === true函数是example .doSomethingElse() .then(something => { example.createSomething(something) });
2 回答
开满天机
TA贡献1786条经验 获得超13个赞
您可以使用 Promise.all 方法
let cleaRoom = function(){
return new Promise(function(resolve, reject){
resolve('room is cleaed')
})
}
let removeGarbage = function(message){
return new Promise(function(resolve, reject){
resolve(message + ' garbage is removed')
})
}
let wonIcecream = function(message){
return new Promise(function(resolve, reject){
resolve(message + ' won the icecream');
})
}
Promise.all([cleaRoom(),removeGarbage(),wonIcecream()]).then(function(){
console.log('finished all');
})
添加回答
举报
0/150
提交
取消