Created
November 4, 2012 05:44
-
-
Save guipn/4010476 to your computer and use it in GitHub Desktop.
Function.prototype.then
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
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