Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created August 17, 2014 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/3681ae504715563f5f9f to your computer and use it in GitHub Desktop.
Save barneycarroll/3681ae504715563f5f9f to your computer and use it in GitHub Desktop.
Just rediscovered function composition.
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