Posts

Showing posts with the label generators

ES-6 Generators

Code for this and several other ES-6 features can be found in my  github Introduction: Generators have been introduced in Java script as a part of the latest ES6 release. This feature offers significant advantages in asynchronous programming. The Legacy stuff: Functions in Java script (or in most languages) have been a bunch of instructions which start with a single motive- which is to execute the instructions and race to completion. Let us consider for example: var add = function (a, b){ if(a < 0) a = a*-1; if(b < 0) b = b *-1; return a+b; } The add function declared above is a simple function which takes two input parameters. Checks if any of them is negative. If it is negative it makes it positive. Adds the two numbers and returns their sum. Basically, once the add function starts execution, it just runs. Any change that happens around it can influence it in no way. If a developer wants the add function to behave differently, the developer has to ...