Created
November 15, 2014 03:49
-
-
Save poying/e3f442b29672526d7709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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