Callback 接口变成 Promise 接口
2019-12-10 本文已影响0人
织雪纱奈
let promisify = (fn, receiver) => {
return (...args) => {
return new Promise((resolve, reject) => {
fn.apply(receiver, [...args, (err, res) => {
return err ? reject(err) : resolve(res);
}]);
});
};
};