gpt4 book ai didi

javascript - .then 不是函数

转载 作者:行者123 更新时间:2023-11-30 07:53:28 24 4
gpt4 key购买 nike

为什么这行是有效的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com