1 /** 2 * @fileOverview This file contains the JS 1.7+ Array iterator 3 */ 4 5 /** 6 * Define an array iterator. 7 * Using this we never need to hide properties from loops and both for and 8 * for each loop syntax become available for looping over arrays while 9 * guaranteeing that they will also always iterate in order. 10 * 11 * @example 12 * for each ( var item in [1, 2, 3] ) 13 * print(item); // Prints 1 then 2 then 3 14 * 15 * @example 16 * for ( var key in [1, 2, 3] ) 17 * print(key); // Prints 0 then 1 then 2 18 * 19 * @methodOf Array 20 * @name __iterator__ 21 */ 22 Array.prototype.__iterator__ = function(isKeys) { 23 for( let i = 0, l = this.length; i<l; ++i ) 24 yield isKeys ? i : this[i]; 25 }; 26 27