0

I have a JavaScript function with unlimited arguments that also has an inside function that uses this arguments. Something like the function in this StackOveflow post which is

function StringCon(arg) {
    var f = function(x) {
        return StringCon(arg + x);
    };
    // var f = StringCon.bind(this, arg + x);

    f.value = arg;

    return f;
}

StringCon("I ")("am ")("new ")("to")(" JavaScript")
.value // -> "I am new to JavaScript"

I actually want to check where does this infinite currying ends. In the above example, I want to check when I get to the last call ("Javascript").

Actually I want to use this check in order to not use .value . I actually want to use StringCon("I ")("am ")("new ")("to")(" JavaScript") to get the "I am new to JavaScript" String itself, not a function which contains an attribute named value. So a I can actually use StringCon("HI)("HI") + StringCon("BYE")("BYE")

Is there any way to do this?

amir na
  • 217
  • 1
  • 13
  • 2
    No, it’s impossible. – Ry- Nov 12 '19 at 21:40
  • I think slebetman’s answer in the linked question is pretty applicable. Note: the implicit versions where you override `valueOf` or `toString` are not good design. – Ry- Nov 12 '19 at 21:43

0 Answers0