Compare Revisions

New in JavaScript 1.7

Revision 51894:

Revision 51894 by Norrisboyd on

Revision 51895:

Revision 51895 by Derickso on

Title:
New in JavaScript 1.7
New in JavaScript 1.7
Slug:
JavaScript/New_in_JavaScript/1.7
JavaScript/New_in_JavaScript/1.7
Tags:
JavaScript, JavaScript_version_overviews
JavaScript, JavaScript_version_overviews
Content:

Revision 51894
Revision 51895
tt127    <h5 name="Generator_Example">
128      Generator Example
129    </h5>
130    <p>
131      This code drives a generator that will yield every 100 loop
 >s.
132    </p>
133    <pre>
134var gen = generator();
135 
136function driveGenerator() {
137        if (gen.next()) {
138                window.setTimeout(driveGenerator, 0);   
139        } else {
140                gen.close();    
141        }
142}
143 
144function generator() {
145        while (i &lt; something) {
146                /** stuff **/
147 
148                ++i;
149                /** 100 loops per yield **/
150                if ((i % 100) == 0) {
151                        yield true;
152                } 
153        }
154 
155        yield false;
156}
157</pre>

Back to History