I started using Javascript a lot more, and as a result I write things complex enough that organization becomes a problem. However, this question applies to any language that allows you to install functions. Essentially, when should you use an anonymous function over a named global or internal function?
At first I thought it was the coolest feature, but I think I'm overboard. Here is an example I wrote recently, ommiling all decation variables and conventions so you can see the structure.
function printStream() {
return fold(function (elem, acc) {
...
var comments = (function () {
return fold(function (comment, out) {
...
return out + ...;
}, '', elem.comments);
return acc + ... + comments;
}, '', data.stream);
}
I realized, although (I think) some beauty is being so compact, itβs probably not a good idea to do it the same way you wouldnβt want tons of code in a double loop,