crop_rotate
Run
<!DOCTYPE html> <html> <body> <h2>JavaScript Iterables</h2> <p id="demo"></p> <script> // Create an Object myNumbers = {}; // Make it Iterable myNumbers[Symbol.iterator] = function() { let n = 0; done = false; return { next() { n += 10; if (n == 100) {done = true} return {value:n, done:done}; } }; } // Create an Iterator let iterator = myNumbers[Symbol.iterator](); let text = "" while (true) { const result = iterator.next(); if (result.done) break; text += result.value +"<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>
PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg0KPGgyPkphdmFTY3JpcHQgSXRlcmFibGVzPC9oMj4NCg0KPHAgaWQ9ImRlbW8iPjwvcD4NCg0KPHNjcmlwdD4NCi8vIENyZWF0ZSBhbiBPYmplY3QNCm15TnVtYmVycyA9IHt9Ow0KDQovLyBNYWtlIGl0IEl0ZXJhYmxlDQpteU51bWJlcnNbU3ltYm9sLml0ZXJhdG9yXSA9IGZ1bmN0aW9uKCkgew0KICBsZXQgbiA9IDA7DQogIGRvbmUgPSBmYWxzZTsNCiAgcmV0dXJuIHsNCiAgICBuZXh0KCkgew0KICAgICAgbiArPSAxMDsNCiAgICAgIGlmIChuID09IDEwMCkge2RvbmUgPSB0cnVlfQ0KICAgICAgcmV0dXJuIHt2YWx1ZTpuLCBkb25lOmRvbmV9Ow0KICAgIH0NCiAgfTsNCn0NCg0KLy8gQ3JlYXRlIGFuIEl0ZXJhdG9yDQpsZXQgaXRlcmF0b3IgPSBteU51bWJlcnNbU3ltYm9sLml0ZXJhdG9yXSgpOw0KDQpsZXQgdGV4dCA9ICIiDQp3aGlsZSAodHJ1ZSkgew0KICBjb25zdCByZXN1bHQgPSBpdGVyYXRvci5uZXh0KCk7DQogIGlmIChyZXN1bHQuZG9uZSkgYnJlYWs7DQogIHRleHQgKz0gcmVzdWx0LnZhbHVlICsiPGJyPiI7DQp9DQoNCmRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJkZW1vIikuaW5uZXJIVE1MID0gdGV4dDsNCjwvc2NyaXB0Pg0KDQo8L2JvZHk+DQo8L2h0bWw+