Promise 函数编程




接下来,getInfoByModal就可以通过直接调用模态框来轻松获取用户填写的数据。 




let resolveFn;
let rejectFn;

function getComLogic() {
  /** isShowBoing:true  */
  let p: {[k: string]: any} = new Promise((resolve, reject) => {
    resolveFn = resolve;
    rejectFn = reject;
  });

  p._data = {
    d1: 'data1',
    d2: 'data2',
  };
  return p;
}

(async () => {
  let p = await getComLogic();
  console.log(p);
})();

/**
 * click event
 */
setTimeout(() => {
  /**
   * 用户操作,eg: 点击弹窗,输入信息
   */
  resolveFn(getComLogic()._data);
}, 1000);

你可能感兴趣的:(js,javascript)