On Tue, Jul 30, 2013 at 3:39 PM, Andrew Fedoniouk <[email protected]
> wrote:

> Slightly different approach that I've found [1] quite useful.
>
> Consider this simple function:
>
> function range(start,end) {
>        var i = start;
>        return function() {
>           if( i < end ) return i++;
>        }
> }
>
> It returns so called iterator function (not an Iterator but just a
> function).
>
> and imagine that for/in ( or for/of )
>
>    for(var el in something)
>
> statement is modified to support functions as collections. So body of
> the for loop is called until function
> `something` returns anything but not void.


> Having this this we can write something like this:
>
>    for(var i in range(12,48))  {
>        console.log(i);
>   }
>
> In principle this simple change eliminates need of most of
> generator/yield cases.
>


Which is exactly this:

function * range(start, end) {
  for (var i = start; i <= end; i++) {
    yield i;
  }
}

for (var value of range(0, 9)) {
  console.log( value );
}


Or do you mean to say that generator functions and yield should be removed?


Rick
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to