<分区>
根据 Mozilla , await 只等待 Promises:
[rv] Returns the resolved value of the promise, or the value itself if it's not a Promise.
如果您等待非 Promise,将立即返回已解决的 Promise,并且不会等待。但是,以下代码在 Chrome 和 FF 中不使用 Promises 等待。
var obj = {
then:func => obj.func=func
};
setTimeout(() => obj.func(57), 1000);
async function go() {
var res = await obj;
console.log(res); //shows '57' after 1000ms
}
go();
根据规范,是否应该等待不是 Promises 的类似 promise 的对象? (我试着查看规范(链接自 Mozilla 文章),但我无法理解。)