title: Passing a string to Function.prototype.apply() JavaScript
body: <p>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.</p>
  
  <p>I would like my code to function somewhat as follows.</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>I would like this to produce the output to the console:</p>
  
  <pre><code>My name is Dean Brunt and my species is Human
  String 1: A string
  String 2: Some other input string, oh yes
  </code></pre>
  
  <p>However, this does not work as <code>Function.prototype.apply()</code> 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.</p>
  
  <p>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.</p>
  
  <p>Many thanks.</p>