Posts

Showing posts from March, 2016

Utilizing ES6 Generator

I am going through Mozilla documentation about the Iterator and Generator concept introduced in ECMAScript6. Here is the overview as per Mozilla JS guide Processing each of the items in a collection is a very common operation. JavaScript provides a number of ways of iterating over a collection, from simple for loops to map() and filter(). Iterators and Generators bring the concept of iteration directly into the core language and provide a mechanism for customizing the behavior of for…of loops. This post is not about how it works, it is better explained at Mozilla JS guide . I have tried to apply the JS generator for one of the our day to day code. I think it is better suitable for lazy traversing and evaluating each item and proceed further if required. A common example comes in my mind is the tree traversing. I have implemented Depth First Search ( pre-order) using generator. Consider the scenario where you need to traverse the tree node, evaluate/process t