Created
September 22, 2011 10:04
-
-
Save joshnesbitt/1234453 to your computer and use it in GitHub Desktop.
Turning a functions arguments into an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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