Re:Functions Should Be Short And Sweet, But Why?
by lucaspiller on Wednesday January 22, 2014 @02:49AM
(#7101349)
I've been doing this in client side Javascript for the last year or so. Rather than having 20 lines of nested jQuery callbacks on a page, I make each callback a function and group the event bindings together:
e.g.:
var showPreview = function() { ... };
var calculate = function() { ... };
$('a.preview').click(showPreview);
$('a.calculate').click(calculate);
Even nicer is to split this out into a separate CoffeeScript file. Then just call `new SuperAwesomeCalculator()` on the page.
I think what made me do this was Erlang. After a point it gets annoying to type NewNewNewNewNewParams, so it's easier just to split it out into a separate function :)
e.g.:
Even nicer is to split this out into a separate CoffeeScript file. Then just call `new SuperAwesomeCalculator()` on the page.I think what made me do this was Erlang. After a point it gets annoying to type NewNewNewNewNewParams, so it's easier just to split it out into a separate function :)