Java Reference
In-Depth Information
The generator object is now stored in the sequence variable. It inherits a method called
next() , which is then used to obtain the next value produced by the yield command:
sequence.next();
<< 2
sequence.next();
<< 3
sequence.next();
<< 5
It's also possible to iterate over the generator:
for (n of sequence) {
// stop the sequence after it reaches 100
if (n > 10)
break;
console.log(n);
}
<< 8
<< 13
<< 21
<< 34
<< 55
<< 89
Note that the sequence continued from the last value that had been produced using the
next() method. This is because a generator will maintain its state throughout the life of
a program.
Modules Using Export and Import
Harmony will support modules natively. The main implementation of modules so far has
been in CommonJS and RequireJS; the notation used by Harmony tries to use the best fea-
tures of both these approaches. The notation uses named exports to highlight anything in a
library that's to be exported. This is done by placing the keyword export in front of any
declaration. For example, if we had a script called average.js containing the sum()
Search WWH ::




Custom Search