functional refactoring: love when this happens

So, nice… 😉

function run(ctx) {
var i;
for(i=0; i<stash.length; i++) {
if(logBefore) {
trace(stash[i], ctx);
}
stash[i](ctx);
if(logAfter) {
trace(stash[i], ctx);
}
}
}
// becomes :->
function run(ctx) {
fn.each(function(f) { fn.compose(trace(f, 'before'), f, trace(f, 'after'))(ctx); }, stash);
}
//happy
view raw refactor.js hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: