// 为Promise添加finally方法支持
Promise.prototype.finally = function (callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then(() => {
throw reason
})
);
};
// 把小程序函数变成promise函数
const promisify = (fn) => {
return (options, ...params) => {
return new Promise((resolve, reject) => {
fn(Object.assign({}, options, {
success: resolve,
fail: reject
}), ...params);
});
}
};