我正在尝试编写一些让我调用承诺函数或更多内部函数的函数。
我现在正在做的是这样的
myFunction(){
this.function1().then(data1=>{
this.function2().then(data2=>{
//do something
})
});
}
function1(){
return new Promise (response=>{
//do something
response(data1);
})
}
function2(){
return new Promise (response=>{
//do something
response(data2);
})
}
有什么简单的方法可以在 myFunction() 中运行 function1() 和 function2() 吗?
编辑:
我需要一些如何编写 1 个函数而不是像这样的 3 个函数
myFunction(){
//something here to return data1 and continue
//same thing here to return data2 and continue
//do something
}