javascript - What is the 'iterator' function in Firebug? -


in firebug, when looking @ getelementsbytagname array, of type htmlcollection see following functions listed:

  • item()
  • iterator()
  • nameditem()

i know how use item(number of item) , nameditem(name of item). use of iterator() ?

i couldn't find answer, i'm asking here.

it's method javascript calls when iterate on object using for…of loop, instance.

see: http://wiki.ecmascript.org/doku.php?id=harmony:iterators#for-of_loop_bodies

an example:

var myobj = {   iterator: function() {     (let = 0; < 5; i++)       yield i;   } }  (let value of myobj)   console.log(value); 

see yield.

in case of htmlcollection helps write code like:

let divs = document.getelementsbytagname("div");  (let div of divs) {   // `div` } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -