Skip to content

Instantly share code, notes, and snippets.

@callmehiphop
Last active October 5, 2016 19:38
Show Gist options
  • Save callmehiphop/c3145ecd142bd18300d53d0c828000bf to your computer and use it in GitHub Desktop.
Save callmehiphop/c3145ecd142bd18300d53d0c828000bf to your computer and use it in GitHub Desktop.
simple Promise#spread decorator
function decorate(Promise) {
Promise.prototype.spread = function(yep, nope) {
var args = [yep ? resolver(yep) : null];
if (nope) {
args.push(resolver(nope));
}
return this.then.apply(this, args);
};
function resolver(cb) {
return function(things) {
things = Array.isArray(things) ? things : [things];
return cb.apply(null, things);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment