How to convert array object to arguments in javascript -
How to convert array object to arguments in javascript -
i have class this:
enum = function() { (var = 0, len = arguments.length; < len; i++) { var k= arguments[i]; this[k] = i; } object.freeze(this); };
to create enum of string, phone call : var options = new enum("eat","drink","sleep"); // many arguments
if have array of arguments stored in variable. ex: var arg_array = ["eat","drink","sleep"]
, how pass new enum(...)
use function.prototype.apply
:
var = {}; enum.apply(a, ["eat","drink","sleep"]);
will give you:
{ "eat": 0, "drink": 1, "sleep": 2 }
javascript arrays arguments
Comments
Post a Comment