Skip to content

Instantly share code, notes, and snippets.

@bjoerge
Last active December 25, 2015 00:19
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 bjoerge/6886658 to your computer and use it in GitHub Desktop.
Save bjoerge/6886658 to your computer and use it in GitHub Desktop.
function combine() {
var funcs = Array.prototype.slice.call(arguments, 0);
return function(obj) {
var _this = this;
return funcs.reduce(function(v, func) {
return func.call(_this, v);
}, obj)
}
}
// Now this
[1,2,3,4]
.map(function plusOne(i) {
return i+1;
})
.map(function timesTwo(i) {
return i*2;
});
// can be rewritten as
[1,2,3,4]
.map(combine(function plusOne(i) {
return i+1;
},
function timesTwo(i) {
return i*2;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment