DEV Community

Discussion on: Closures and Callbacks

Collapse
 
flexdinesh profile image
Dinesh Pandiyan • Edited

Oh man, I finally found a convincing example to curry functions in javascript. I'm not sure why you call it closure though (I've never been able to wrap my head around the word - so many different explanations). But this is definitely function currying.

Thanks for this amazing example :)

Collapse
 
rpalo profile image
Ryan Palo

Hey, glad you liked it, thanks for the feedback!

As far as I know, a closure is anytime you wrap a function in an outer scope and return it, such that that function has access to the outer scope long after that outer scope has ended.

After doing some reading, it looks like currying is when you break a multi-parameter function into a series of nested functions and you end up only passing in one thing at a time? In which case, it would seem like currying is just one specific example in the broader case of closures. Let me know if that sounds right or if I'm missing something.

If you haven't already, you might like to take a look at an article I wrote a few weeks ago that goes more into detail about closures. The code examples are in Python, but I think the point still comes across.

Thanks again!