Skip to content

Instantly share code, notes, and snippets.

@joshnesbitt
Created September 22, 2011 10:04
Show Gist options
  • Select an option

  • Save joshnesbitt/1234453 to your computer and use it in GitHub Desktop.

Select an option

Save joshnesbitt/1234453 to your computer and use it in GitHub Desktop.
Turning a functions arguments into an array
var test = function(){
var args = arguments;
args.push(4);
console.log(args);
}
// Results in a TypeError, as arguments isn't actually an array object.
// To coerce arguments to an array, call Array's slice method:
var test = function(){
var args = Array.prototype.slice.call(arguments);
args.push(4);
console.log(args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment