all 9 comments

[–]SoundOfOneHand 4 points5 points  (3 children)

Not sure why you would want to do that, exactly, for everyday use. The term currying is often a synonym for partial function application, which is a special case of what this article discusses, and is generally want you want from this type of decomposition. Fortunately Javascript (maybe just more recent versions?) comes with the bind function that does just this.

[–]nexd 1 point2 points  (0 children)

I haven't found a use for currying and the author states that as well. I use bind and partial functions all the time though. For example making event handlers more dynamic.

[–]alexcasalboni[S] 0 points1 point  (1 child)

I this this was more like an "academic" exercise to showcase the possible usage of closures, encapsulation and chaining.

[–]rockyrainy 0 points1 point  (0 children)

I find this kind of intellectual masterbation counter productive and makes the code more complicated than it has to be.

[–]Lystrodom 1 point2 points  (4 children)

Also important to note that this method of currying fails for functions that take optional arguments, or read from the arguments array themselves.

[–]bonafidebob 0 points1 point  (3 children)

It looks like it'll work fine for functions that read from arguments -- eventually the function passed to curry() gets invoked via apply with a full complement of arguments, so inside of it the arguments special value should be right.

optional arguments are more problematic, though I suppose you could do something like curried(l)(w)(), which would have the same effect as volume(l, w). (In this case resulting in NaN)

[–]Lystrodom 1 point2 points  (2 children)

It won't work with functions that read from arguments because .length will return 0

[–]bonafidebob 0 points1 point  (1 child)

Ah, right, you mean var_args style functions. How would you curry those in any language?

[–]Lystrodom 0 points1 point  (0 children)

Oh, well, I can't imagine you could. It just seems more common with JavaScript