Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Since you can define a function inside a function, why does it matter that it isn't anonymous?


sort by: page size:

Why are people so concerned about anonymous functions? The facts that you ca Defoe a function inside a function, and that they are object make named functions as good as anonymous ones.

It lets you define functions on the fly and use them, so the only difference from anonymous functions is that you have to pick a name.

> Anonymous functions are vital to any modern high level language.

I don’t think you’re wrong, but I am also not experienced enough to know why this would be the case. What is the virtue of having an anonymous function? I get that it makes code somewhat easier to read and write if you’re only using the function once and it’s short, but that seems like an edge case. What am I missing?


Can you not `func(foo){}`? Because that is what would bother me.

`func(foo){}` and `(foo) ->` seem too similar, for my taste at least. Sure, the difference is that one is always anonymous, where as one is sometimes anonymous.. but we've been using `function` as both named and anonymous for ages


why does this matter, what is the overwhelming use case for self referential anonymous functions.

Why do you consider anonymous functions so important? Regular functions can be used the same way?

This is the silliest thing I see paroted. Anonymous functions are there for one offs. Sometimes a one-off is two lines. Breaking it out into a separate function is ridiculous.

You end up seeing functions declared within functions so that people can work around this limitation and it is grotesque.


Anonymous functions can generally be abused in ways that make code harder to read. Then again, so can recursion. It's a double edged sword.

Can someone please explain where an anonymous function has an advantage over a named function? (Not trolling: I'm really trying to figure it out.)

Anonymous functions?

Honest question: If you are making an anonymous function longer than one line, shouldn't you just make a normal function? What are the use cases for large anonymous functions?

I don't really get why people are so excited about anonymous functions.

First class functions may be exciting. Not having to give a name to your functions, is not.


... and it will also make them not anonymous functions :)

I just don't understand where you would need an anonymous function with more then one line

For the sake of understanding that a function is a function, let's declare them. Arrow functions are awesome as anonymous functions.

Fair, but seems inconsistent to have `fn` instead of `function` like we use for anonymous functions - unless `fn` acts like an alias to `function` now (which doesn't sound like is the case) which wouldn't be as ambiguous for the compiler to figure out

Anonymous functions as an expression do have their purpose, unlike the author has stated, especially when you want to isolate different blocks of code from each other by putting them each in a different scope.

but the inner function is not anonymous, which is the focus of the question.

I see what you meant now. Though it seems you are mixing notions of anonymous function and function as an argument of higher order functions (it doesn't have to be anonymous).
next

Legal | privacy