NoFunctionCallsChainingDRAFT
It is never allowed to chain function calls, as in f(2)(3)
.
It is not allowed to chain function calls
Multiple function calls can be chained together
CorrectionHere is what's right.
An expression like f()(3)
is evaluated from left to right: firstly the function f
gets called with no arguments. The resulting value, which we expect to be a function, is then called passing 3
as the first and only argument. The return value of this last call is the value which the overall expression evaluates to.
When calling f()
does not produce a function but something else (e.g., a regular number), we get an error.
If instead we exploit the fact that in JavaScript functions are values, f
can return a function which in turn can be legally called as shown above and as further demonstrated in the next example.