Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ES6 Iterators and Generators

node v0.12.18
version: 1.0.0
endpointsharetweet
ES6 introduced the new for...of construct to iterate over collections:
// For...of will give us the items instead of the indexes. for (var item of [2,4,6,8]) console.log(item)
With iterators, your own custom collections can define how they behave in for...of. Simply assign an iterator method to a property with the global iterator symbol:
var cart = { items: ["pizza", "car", "pastrami"], [Symbol.iterator] : function () { var index = 0; var length = this.items.length; return { next: () => { if (index < length) return { value: this.items[index++], done: false }; return { value:null, done: true }; } } } } for (item of cart) console.log(item + " is in your cart!");
Generators allow you to write the same code in a much less verbose way:
var cart = { items: ["pizza", "car", "pastrami"], [Symbol.iterator] : function* () { for (var index = 0; index < this.items.length; ++index) yield this.items[index]; } } for (item of cart) console.log(item + " is in your cart!");
Learn more about iterators here: https://hacks.mozilla.org/2015/04/es6-in-depth-iterators-and-the-for-of-loop/ Leran more about generators here: https://hacks.mozilla.org/2015/05/es6-in-depth-generators/
Loading…

52 comments

  • posted 2 years ago by 6473519fc0a4050008c8cf99
    اگر میشود کیف پول را همیشه ذخیره داشته باشیم
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    -1 OR 2+858-858-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1 OR 2+220-220-1=0+0+0+1
  • posted a month ago by xsjybldb
    -1' OR 2+445-445-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1' OR 2+805-805-1=0+0+0+1 or 'kVpP03ka'='
  • posted a month ago by xsjybldb
    -1" OR 2+498-498-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted a month ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted a month ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted a month ago by xsjybldb
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted a month ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    xEy9PNY7'; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -5 OR 577=(SELECT 577 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -5) OR 744=(SELECT 744 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -1)) OR 771=(SELECT 771 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    ttQkYRuj' OR 250=(SELECT 250 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    DR3aHb42') OR 109=(SELECT 109 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    zkiqvA28')) OR 292=(SELECT 292 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted a month ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted a month ago by xsjybldb
    1'"
  • posted a month ago by xsjybldb
    @@77OiI
  • posted 25 days ago by 67478559714940000843b0a0
    1
  • posted 25 days ago by 67478559714940000843b0a0
    1
  • posted 25 days ago by 67478559714940000843b0a0
    -1 OR 2+965-965-1=0+0+0+1 --
  • posted 25 days ago by 67478559714940000843b0a0
    -1 OR 2+283-283-1=0+0+0+1
  • posted 25 days ago by 67478559714940000843b0a0
    -1' OR 2+532-532-1=0+0+0+1 --
  • posted 25 days ago by 67478559714940000843b0a0
    -1' OR 2+472-472-1=0+0+0+1 or 'yz0S7sDX'='
  • posted 25 days ago by 67478559714940000843b0a0
    -1" OR 2+170-170-1=0+0+0+1 --
  • posted 25 days ago by 67478559714940000843b0a0
    1*if(now()=sysdate(),sleep(15),0)
  • posted 25 days ago by 67478559714940000843b0a0
    10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 25 days ago by 67478559714940000843b0a0
    10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 25 days ago by 67478559714940000843b0a0
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted 25 days ago by 67478559714940000843b0a0
    1-1; waitfor delay '0:0:15' --
  • posted 25 days ago by 67478559714940000843b0a0
    1-1); waitfor delay '0:0:15' --
  • posted 25 days ago by 67478559714940000843b0a0
    1-1 waitfor delay '0:0:15' --
  • posted 25 days ago by 67478559714940000843b0a0
    1tqo0H8JY'; waitfor delay '0:0:15' --
  • posted 25 days ago by 67478559714940000843b0a0
    1-1 OR 447=(SELECT 447 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1-1) OR 156=(SELECT 156 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1-1)) OR 670=(SELECT 670 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1hpoa6mZQ' OR 35=(SELECT 35 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1abI9F1Av') OR 797=(SELECT 797 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1oMd4psr0')) OR 644=(SELECT 644 FROM PG_SLEEP(15))--
  • posted 25 days ago by 67478559714940000843b0a0
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 25 days ago by 67478559714940000843b0a0
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 25 days ago by 67478559714940000843b0a0
    '"
  • posted 25 days ago by 67478559714940000843b0a0
    ����%2527%2522\'\"
  • posted 25 days ago by 67478559714940000843b0a0
    @@BmYU0

sign in to comment