gpt4 book ai didi

javascript - 未捕获的类型错误 : undefined is not a promise

转载 作者:可可西里 更新时间:2023-11-01 02:30:55 24 4
gpt4 key购买 nike

我得到了错误 Uncaught TypeError: undefined is not a promise

const p = Promise((resolve, reject) => {
resolve('ok')
})

p.then(resp => console.log(resp))

https://jsbin.com/daluquxira/edit?js,console,output

上面的代码有什么问题?

最佳答案

您需要实例化 Promise

在这种情况下:

const p = new Promise((resolve, reject) => {
resolve('ok')
})

p.then(resp => console.log(resp))

关于javascript - 未捕获的类型错误 : undefined is not a promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47469367/

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