how to make this syntax possible in node.js console (javascript) -
this question has answer here:
- variadic curried sum function 7 answers
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 make possible?
you can use tostring
/valueof
method treat result value.
function sum(a) { chain.valueof = function() {return a;} return chain; function chain(s) { += s; return chain; }; } sum(7)(3)(5) == 15 // true sum(7)(3) + 5 == 15 // true +sum(7)(3)(5) // 15
Comments
Post a Comment