未捕获的TypeError:undefined不是一个承诺

时间:2017-11-24 08:41:50

标签: javascript ecmascript-6

我收到了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

上述代码有什么问题?

1 个答案:

答案 0 :(得分:18)

您需要实例化Promise

在这种情况下:



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

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