Last active
August 29, 2015 14:22
-
-
Save MrAntix/db79994dbc0131e07da9 to your computer and use it in GitHub Desktop.
js param array
This file contains 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 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' |
This file contains 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 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