最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript等待设置对象属性

运维笔记admin11浏览0评论

Javascript等待设置对象属性

Javascript等待设置对象属性

getStore().then((store) => {
  buildRates().then((rates) => {
    let newStore = store;
    newStore.rates = rates;
    setStore(newStore).then((res) => {
      // callback
      cb(null, res);
    })
  })
});

在async / await语法中写这个有困难。当我试着写这样的等待......

let store = await getStore();
store.rates = await buildRates();
setStore(store).then((res) => {
  // callback
  cb(null, res);
});

... setStore使用从await getStore()返回的原始对象,没有来自store.ratesawait buildRates()上的对象

有任何想法吗?

回答如下:

解决了。问题是buildRates()不是一个正确的承诺,哎呀!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论