Last active
July 13, 2016 13:14
-
-
Save alvieirajr/b52e646df2c879a9aa04bcb07ed30dc0 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
// Simple compose example (extract from Scott Sauyet) | |
// Simplest compose | |
var compose = function(f, g) { | |
return function(x) { | |
return f(g(x)); | |
}; | |
}; | |
var trim = function(str) {return str.replace(/^\s*|\s*$/g, '');}; | |
var capitalize = function(str) {return str.toUpperCase();}; | |
var convert = compose(trim, capitalize); | |
console.log('"' + convert(' abc def ghi ') + '"'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drawbacks:
It loses track of the this context used to call it.
It ignores all but the first argument passed to the initial function.