Skip to content

Instantly share code, notes, and snippets.

@MrAntix
Last active August 29, 2015 14:22
Show Gist options
  • Save MrAntix/db79994dbc0131e07da9 to your computer and use it in GitHub Desktop.
Save MrAntix/db79994dbc0131e07da9 to your computer and use it in GitHub Desktop.
js param array
var someFunction = function(text, moreThings) {
var moreThingsArray = paramArray(moreThings, arguments, 1);
// ... do stuff
};
someFunction('test with array', [new thing(), new thing()]);
someFunction('test with params', new thing(), new thing());
// both of the calls will end up with an array of two things in 'moreThings'
// when you get to 'do stuff' in 'someFunction'
var paramArray = function (array, args, index) {
if (Array.isArray(array)) return array;
var argumentsArray = [];
for (var ai = index; ai < args.length; ai++) {
argumentsArray.push(args[ai]);
}
return argumentsArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment