its not 100% clear on what you want but here is a quick example of what i think your asking for(它不是100%清楚您想要什么,但这是我认为您要求的简单示例)
so to make your function use promises instead of callback you could do something like this(为了使您的函数使用Promise而不是回调,您可以执行以下操作)
function promiseFunction(){
return new Promise(resolve =>{
resolve(result);
}
}
and when you want to get the data that the function returns you could do this(当您想要获取函数返回的数据时,可以执行此操作)
function getInfoFromFunction(){
promiseFunction(arg).then(result => {
console.log(result)
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…