The latest version of JavaScript allows you to pass variables, arrays and iterators into a function using code such as:
var a = 1;
var b = [2,3];
var c = [4,5,6].values();
fn(a, ...b, ...c);
The ES2015 spread operator (eg ...c) is not recognised in older versions of JavaScript. While we can't get old versions of JavaScript to recognise this new syntax, we can implement a similar syntax to achieve the same end result.
By implementing this spread method we can make a milor change to the above code and have it run in any version of JavaScript.
var a = 1;
var b = [2,3];
var c = [4,5,6].values();
fn.__(a, b, c)
Bonus
-----
Generate iterators from arrays with these polyfills (not found in any of the usual places you'd look for polyfills)
Array.entries( ) - returns an array Iterator object containing key/value pairs for each entry in the array.
Array.keys() - returns an array Iterator object containing the key for each entry in the array.
Array.values() - returns an array Iterator object containing the value for each entry in the array.
|