What is the cleanest way to use anonymous functions?

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,

+3
3

, . , . , .

, 2 3-, .

JavaScript, , .

, " ", . , " ".

+1

, .

, , ( ...), / .

/ , . , - ,

+1

, . .

- , , , .

, .

( : {} ).

+1

Source: https://habr.com/ru/post/1746577/


All Articles