(
(
(f) => f(f)
)
(
(f) =>
(l) => {
console.log(l)
if (l.length) f(f)(l.slice(1))
console.log...
For further actions, you may consider blocking this person and/or reporting abuse
Hi. Thank you.
Only one suggestion: maybe the "self executing function" should be:
That would work too. And it's looking good.
Not only, but it better separates the code term (one) from the input terms (two of them).
In my version, you can see that all the long consecutive block:
is the code term as a whole, and the next two terms are inputs.
Getting all the "input" as a whole ensures portability (that is, you can take that self-sufficient code and use somewhere else).
For any novice reader of my reply: in JavaScript (and, more in general, in classical lambda-calculus theory), the convention is to left-associate terms together in more-than-two-items sequences, so the two input terms cannot be grouped in one term only (like we did for the code one).
A fully parenthesiszed equivalent expression would be:
indeed.
The outermost parentheses, in my notation, indicates that we want to reduce (or, in classical programming languages speaking, to run) what's inside of them.
Regarding my first reply, I was just comparing your version of the invocation code (the one with the 'dev.to' term inside the function to be returned) with this other invocation
foo('hey')('dev.to')
you wrote right before.
Simply, my version applies the arguments like this 😊.
Regards.
Now I see, I was looking at the Going Deep example where I intentionally wanted to nest the arguments, so that the example resembles more closely the Anonymous Recursion one below it.
I should probably update the example in the Closures chapter. Thanks for the feedback!
Correct me if I'm wrong.
Function that returns another function is high order function not a closure. Closure relates to scope and not to return.
That is absolutely correct, a closure has access to the function environment (scope) of it's parent. A higher-order function can be described as a function that accepts a function as an argument and/or returns a function.
Thank you for your input!
I've fixed the definition, this time I got it straight from MDN just to make sure I'm not mistaken something.
Usually this is a perfect example howto to not write code. But for an interview it's great!
I agree, the anonymous recursion is a bit extreme and hard to maintain, though each part of this example taken separately is actually very useful in day to day programming.
You should bring up the y-combinator in there...
Hi, may i translate your article in Russian and publish it on my resource: lovefrontend.ru/ . I put links to your original article. Thanks.
Sure, if there is a link to the original article - then no problem.