Hacker News new | ask | show | jobs
by danprager 6301 days ago
Yes, in that case the inner function has access to the arguments of the outer function. But you can go deeper -- e.g. declaring an inner function inside code inside the out er function -- which also knows about the local variables in the outer function.

Or if you're only doing it once use a lambda (with the same advantages).

1 comments

Isn't this how you use closures? I think I've been doing this with my javascript code without even noticing it. :-)
Yes, these idioms would work in Javascript too.

I guess the point is that people are starting to discover that languages like Python and JS support these functional idioms quite nicely.

Remember when all the books on JS pretended that it was some kind of crippled cousin of Java (as the name suggests), rather than a Scheme-lite in Java-esque syntax (as its designer has opined).

Haha yes, I do remember those times. Now that you've mentioned it another language that fits the description of a Scheme-lite in Java-esque syntax is Lua.