The same function summ
:
summ(7)(3)(5)
must equal 15
and
summ(7)(3)+5
must equal 15
and
summ(7)(3)
must equal 10
How to make it possible?
The same function summ
:
summ(7)(3)(5)
must equal 15
and
summ(7)(3)+5
must equal 15
and
summ(7)(3)
must equal 10
How to make it possible?
You can use toString
/valueOf
method to treat result as a value.
function sum(a) {
chain.valueOf = function() {return a;}
return chain;
function chain(s) {
a += s;
return chain;
};
}
sum(7)(3)(5) == 15 // true
sum(7)(3) + 5 == 15 // true
+sum(7)(3)(5) // 15