Question: I currently have a need to have a set of function arguments defined as a comma separated string and passed in at a later time.

I would like my code to function somewhat as follows.

```
function bar() {
    console.log("My name is " + arguments[0].name + " and my species is " arguments[0].species);
    console.log("String 1: " + arguments[1]);
    console.log("String 2: " + arguments[2]);
}

function foo() {
    var args = "{name: 'Dean Brunt', species: 'Human'}, 'A string', 'Some other input string, oh yes'";
    bar.apply(null, args);
}

```

I would like this to produce the output to the console:

```
My name is Dean Brunt and my species is Human
String 1: A string
String 2: Some other input string, oh yes

```

However, this does not work as `Function.prototype.apply()` takes an array as its' second argument. Whilst, I have tried converting the args string to an array, I have struggled with this due to the non-trivial regex split this would incur and my attempts have been fruitless.

Could anyone help me define an appropriate regex object I could use for the split or suggest an alternative that would produce the same result.

Many thanks.

Answer: 
It's not pretty, but you can use `eval`:

```js
function bar() {
    console.log("My name is " + arguments[0].name + " and my species is " + arguments[0].species);
    console.log("String 1: " + arguments[1]);
    console.log("String 2: " + arguments[2]);
}

function foo() {
    var args = "{name: 'Dean Brunt', species: 'Human'}, 'A string', 'Some other input string, oh yes'";
    bar.apply(null, eval('[' + args + ']'));
}

foo();
```
You can use eval().
Writing a regex would be quite tedious.

```
function stringToArgs(str){
   return eval(`(function(){return arguments;})(${str})`);
}

function bar(arguments) {
    console.log("My name is " + arguments[0].name + " and my species is " +arguments[0].species);
    console.log("String 1: " + arguments[1]);
    console.log("String 2: " + arguments[2]);
}

function foo() {
    var args = "{name: 'Dean Brunt', species: 'Human'}, 'A string', 'Some other input string, oh yes'";
    bar(stringToArgs(args));
}

foo();

```