Introduction
You may have heard about closures. You most certainly already use them even if you don't fully know what they are. Closures...
For further actions, you may consider blocking this person and/or reporting abuse
Learned a lot! Thanks!
Closure is one of those things which causes my head spinning.
Nice article. Learnt a lot. Thank you.
Glad you found it helpful :)
If anyone does
foo(bar)(baz)
in code I have to maintain, I'm going to be cross.Yeah, I can understand that :D
Very well explained with examples in following link
idontknowjavascript.com/2019/05/cl...
Can anybody explain this to me? cookiesBaker("Sarah")("peanut butter")
Given this is the definition of cookiesBaker function
As you can see here, there's 3 functions, one with two nested functions. each one of em takes a parameter. so we need to call the function with three different nested parameters in order to meet its requirement.
like so
cookiesBaker("Sarah")("peanut butter")("white")
which will return a value of "Sarah cooked a peanut butter white chocolate cookie."How it worked?
cookiesBaker("Sarah")
calling this alone will evaluate and set parameter "cook" equal to "Sarah" then returns a function. in which that function will be called as followingcookiesBaker("Sarah")returnedFunction("peanut butter")
which will evaluate parameter "secretgradient" to "peanut butter" then returns a function that will be called ascookiesBaker("Sarah")returnedFunction("peanut butter")returnedFunctionTwo("white")
which will evaluate parameter "chocolate" to "white" then returns a string value equal to "Sarah cooked a peanut butter white chocolate cookie."