javascript thunk

 thunk 

const Thunk = function(fn) {
  return function (...args) {
    return function (callback) {
      return fn.call(this, ...args, callback);
    }
  };
};
 function f(a, cb) {
  cb(a);
}
const ft = Thunk(f);
console.log(ft)

ft(2)(console.log) // 2

猜你喜欢

转载自my.oschina.net/u/3529405/blog/1814574