Skip to content

Instantly share code, notes, and snippets.

@alvieirajr
Last active July 13, 2016 13:14
Show Gist options
  • Save alvieirajr/b52e646df2c879a9aa04bcb07ed30dc0 to your computer and use it in GitHub Desktop.
Save alvieirajr/b52e646df2c879a9aa04bcb07ed30dc0 to your computer and use it in GitHub Desktop.
// 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 ') + '"');
@alvieirajr
Copy link
Author

Drawbacks:

It loses track of the this context used to call it.
It ignores all but the first argument passed to the initial function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment