Search code examples
javascript

JavaScript Iterators


I was going through MDN (Mozilla Developer Network) and came across Iterators and generators

So naturally, I tried the snippets of code given in the page on Google Chrome v21. To be specific, this code:

var it = Iterator(lang);
for (var pair in it)
  print(pair); // prints each [key, value] pair in turn

However, the console returns this error message:

ReferenceError: Iterator is not defined

Why's that? Is the Iterator function deprecated or something? Am I missing a point? Thank you for your help and time :-)


Solution

  • From this thread:

    V8 is an implementation of ECMAScript, not JavaScript. The latter is a non-standardized extension of ECMAScript made by Mozilla.

    V8 is intended to be plug-in compatible with JSC, the ECMAScript implementation in WebKit/Safari. As such it implements a number of non-standard extensions of ECMAScript that are also in JSC, and most of these are also in Mozilla's JavaScript languages.

    There is no plan to add non-standard features that are not in JSC to V8.

    Note: JSC stands for JavaScript Core - the WebKit ECMAScript implementation.