为什么这行是有效的 promise :
const promise = Promise.resolve('Hello');
但不是这个:
const otherPromise = () => {
return Promise.resolve('Hello');
}
当尝试调用第二个示例时:
function runOtherPromise() {
otherPromise
.then(v => console.log(v));
}
...我收到 TypeError: otherPromise.then is not a function
。不过,它在第一个示例中运行良好。我不明白为什么第二个示例不返回 promise 。
最佳答案
otherPromise 是一个函数,你应该像下面这样调用它:
runOtherPromise() {
otherPromise()
.then(v => console.log(v));
}
关于javascript - .then 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47264281/