The arguments to process, may be ArrayLike or an Iterable
Optionalstart: number
Zero-based index at which to start extraction, converted to an integer.
Optionalend: number
Zero-based index at which to end extraction, converted to an integer. readArgs() extracts up to but not including end.
A new array with the extracted elements
TypeError when a value without a length has a [Symbol.iterator] which isn't a function (a falsy value,
eg. null, is ignored), an iterable's [Symbol.iterator]() doesn't return an iterator, the iterator's next()
returns a value which is not an object, or (like for...of) when it stops early (at the end index) and the
iterator's return() doesn't return an object
function myFunc<T>(firstArg: T, ...otherArgs) {
// Read all of the arguments
let allArgs = readArgs(arguments);
// Get all of the arguments after the first
let optArgs = readArgs(arguments, 1);
}
myFunc("Hello");
myFunc("Hello", "Darkness", "my", "old", "friend", ".");
function* myGenerator() {
yield "Hello";
yield "Darkness";
yield "my";
yield "old";
yield "friend";
}
function* myGenerator2() {
yield "I've";
yield "come";
yield "to";
yield "talk";
yield "with";
yield "you";
yield "again";
}
readArgs(myGenerator());
// [ "Hello", "Darkness", "my", "old", "friend"]);
readArgs(myGenerator(), 1);
// [ "Darkness", "my", "old", "friend"]);
readArgs(myGenerator2());
// [ "I've", "come", "to", "talk", "with", "you", "again" ]);
readArgs(myGenerator2(), 0, -2);
// [ "I've", "come", "to", "talk", "with" ]);
readArgs(myGenerator2(), -3, -2);
// [ "with" ]);
Read the arguments from the provided array, iterator / or generator function When processing an Iterable and a negative start or end is provided the entire iterator will be processed into an array before applying the start / end restrictions and when undefined or >= 0 any iterator will not be fully processed. A
Map(its[key, value]entries) orSet(its values) which isn't iterable (eg. on IE 11, which has no iterator functions) is read (since 0.20.0) from a copy of its entries / values.