How do I check if a JavaScript function returns a Promise?

前端 未结 3 1098
挽巷
挽巷 2020-12-16 05:29

Say I have two functions:

function f1() {
    return new Promise((resolve, reject) => {
        resolve(true);
    });
}

function f2() {
}
         


        
3条回答
  •  再見小時候
    2020-12-16 06:11

    Call the function, use instanceof

    let possiblePromise = f1();
    let isPromise = possiblePromise instanceof Promise;
    

提交回复
热议问题