Search code examples
javascriptargumentsfromcharcode

Adding Multiple Arguments into an built in function, from a function


I'm trying to add String.fromCharCode(). And adding it into a function that renames it like so:

function from() {
    var ar = arguments.length;
    var argumentss = '';
    for (var i = 0; i < ar; i++) {
        var a = argumentss + '\'' + arguments[i];
           if (i == ar - 1) {
               argumentss = a + '\''
           } else {
               argumentss = a + '\', '
           }
    }
    var arg = eval(argumentss);
    return String.fromCharCode(arg)
}

I need to do this, so don't say that there is no reason to do this, since the way im actually using it there is a reason.

What im trying to do is make it possible to do:

from(65,66,67) //returns ABC

Without doing function from(a,b,c)

Since with the fromCharCode you can do as many arguments as you want. It would also be useful if there was a custom fromCharCode function. Thanks


Solution

  • Is this what you want?

    function from() {
        var result = '';
        for (var i = 0; i < arguments.length; i++) {
           result += String.fromCharCode(arguments[i]);
        }
        return result;
    }
    
    from(65,66,67)
    //result ->  ABC