Skip to content

Instantly share code, notes, and snippets.

@poying
Created March 9, 2014 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poying/9444971 to your computer and use it in GitHub Desktop.
Save poying/9444971 to your computer and use it in GitHub Desktop.
var promisfy = function (fn, ctx) {
return function () {
var args = arguments;
return new Promise(function (resolve, reject) {
var cb = function () {
var err = Array.prototype.shift.call(arguments);
if (err) {
reject(err);
} else {
resolve.apply(null, arguments);
}
};
Array.prototype.push.call(args, cb);
fn.apply(ctx || null, args);
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment