小程序Promise

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/** 异步函数回调简化处理
const promisify = require('./promisify')
const getSystemInfo = promisify(wx.getSystemInfo)
 
getSystemInfo().then(res=>{
    // success
    console.log(res)
}).catch(res=>{
 
})
**/
module.exports = (api) => {
  return (options, ...params) => {
    return new Promise((resolve, reject) => {
      console.log(options)
      console.info(...params)
      api(Object.assign({}, options, {
        success: resolve,
        fail: reject
      }), ...params);
    });
  }
}

  

 
posted @   dnoyeb  阅读(379)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示