Let me suggest you using regular expressions:
- [match]
/function[^(]*\(([^)]*)\)/ will match the argument list
- [split]
/\W+/ (against the results of the first match data) will split the match into params list
So, the code should look like this:
var s = "function moo (paramOne, paramTwo) { alert('hello'); }";
var s2 = s.match(/function[^(]*\(([^)]*)\)/)[1];
var paramList = s2.split(/\W+/);