Created
August 17, 2014 21:00
-
-
Save barneycarroll/3681ae504715563f5f9f to your computer and use it in GitHub Desktop.
Just rediscovered function composition.
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 composer(){ | |
var transforms = [].slice.call( arguments ); | |
return function functionWrapper( handler ){ | |
return function transform(){ | |
var ctxt = this; | |
var args = [].slice.call( arguments ); | |
transforms.forEach( function applyTransform( transform ){ | |
transform.apply( ctxt, args ); | |
} ); | |
return handler.apply( ctxt, args ); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment