Javascript Promise返回[object Object]

时间:2019-05-02 09:43:51

标签: javascript

我有一个承诺的功能:

myfunction() {
    return new Promise(function(resolve) {
        try {
            console.log(`In Progress...`);
            }
            catch(err) {
                console.log(`There was an error: ${err}`);
            }
            finally {
                resolve(`Finished`); 
                return 'Finished';
        }

    }); 

}


myfunction().this.getMemory().then(values => {
    return values;
});

它不断返回[object Object]

我没有得到什么返回值?

1 个答案:

答案 0 :(得分:1)

您可以像我不知道有关getMemory函数那样调用

 myfunction() {
    return new Promise(function(resolve) {
        try {
            console.log(`In Progress...`);
            }
            catch(err) {
                console.log(`There was an error: ${err}`);
            }
            finally {
                resolve(`Finished`); 
                return 'Finished';
        }

    }); 

}


return myfunction().then(values => {
  return this.getMemory().then(result=>{
     return values;
}).catch(error=>{})

});