Question

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

Was it helpful?

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

OTHER TIPS

Does this address your problem? Call this once at the beginning:

String.from = String.fromCharCode.bind(String)

and use later:

String.from(65, 66, 67)  //"ABC"

Using built-in String.fromCharCode().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top