Skip to content

Instantly share code, notes, and snippets.

@poying
Created November 15, 2014 03:49
Show Gist options
  • Save poying/e3f442b29672526d7709 to your computer and use it in GitHub Desktop.
Save poying/e3f442b29672526d7709 to your computer and use it in GitHub Desktop.
var supportPromise = function (fn) {
return function () {
if (typeof arguments[arguments.length - 1] === 'function'
|| typeof Promise === 'undefined') {
return fn.apply(this, arguments);
}
var args = arguments;
return new Promise(function (resolve, reject) {
Array.prototype.push.call(args, function (err, res) {
err ? reject(err) : resolve(res);
});
fn.apply(this, args);
}.bind(this));
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment