function arbitraryOnlyArgs() {
console.log(Object.prototype.toString.call(arguments), arguments);
var args = Array.prototype.slice.call(arguments);
console.log(Object.prototype.toString.call(args), args);
}
function mixedArgs(a, b) {
console.log(Object.prototype.toString.call(arguments), arguments);
var args = Array.prototype.slice.call(arguments, 2);
console.log(Object.prototype.toString.call(args), args);
}
If you need to manipulate/handle extra arguments in you functions (eg. sort or walk them), just "slice" them to get all the Array.prototype power.
These examples show how to convert arbitrary Arguments into Arrays.
These examples show how to convert arbitrary Arguments into Arrays.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.