Quote:
Originally Posted by suzzer99
Right. If you define once as “once per line”. You have a stateful function either way. The line break can’t reset it unless you do something special like that empty function call at the end you added.
I'm not sure if I'm misunderstanding you or you're wrong. Caveat: it's my wife's birthday and I'm well into some champagne.
But at the risk of being wrong and or just unnecessarily pedantic, it's not a line break that matters, it's the fact that the way I did it returns a new function for each call, so that you have different objects (functions) with values attached to them. I think this is fairly common for this kind of currying, and you can think of the mult method as a kind of factory.
So you can do things like
Code:
const mult12 = mult(3)(4);
const mult96 = mult(2)(6)(8);
and be sure that they are entirely independent, so that mult12(2).value = 24, and mult96(3).value = 288, etc. They are still effectively pure functions in that sense, and you don't have to know anything about state to understand what they will return.