Answer the question
In order to leave comments, you need to log in
How to implement multiple function call in JavaScript?
Is it realistic to get such a result or not? If yes, how? console.log(add(1)(3)(5)(35)); // 44
There can be any number of calls.
Answer the question
In order to leave comments, you need to log in
Here are some of the examples.
As far as I remember, it is necessary not toString, but valueOf to assign.
Check both options.
function sum(a) {
var currentSum = a;
function f(b) {
currentSum += b;
return f;
}
f.toString = function() {
return currentSum;
};
return f;
}
alert( sum(1)(2) ); // 3
alert( sum(5)(-1)(2) ); // 6
alert( sum(6)(-1)(-2)(-3) ); // 0
alert( sum(0)(1)(2)(3)(4)(5) ); // 15
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question