Skip to content

Instantly share code, notes, and snippets.

@guipn
Created November 4, 2012 05:44
Show Gist options
  • Save guipn/4010476 to your computer and use it in GitHub Desktop.
Save guipn/4010476 to your computer and use it in GitHub Desktop.
Function.prototype.then
function square(x) {
return x*x;
}
function add3(x) {
return x + 3;
}
function sub10(x) {
return x - 10;
}
Function.prototype.then = function(func) {
var that = this;
return function() {
return func(that.apply(null, arguments));
}
}
square.then(add3).then(sub10)(10); // -> 9993
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment