Claes Jakobsson > JavaScript > JavaScript::Generator

Download:
JavaScript-1.16.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  25
Open  12
View/Report Bugs
Source  

NAME ^

JavaScript::Generator - Boxed Perl object of a JavaScript generator

DESCRIPTION ^

Generators were introduced in JavaScript 1.7. When you 'yield' from JS you'll be returned an instance of this class that you can use to retrieve the next value from the generator.

For example

  function fib() {  
    var i = 0, j = 1;  
    while (true) {  
      yield i;  
      var t = i;  
      i = j;  
      j += t;  
    }  
  }  
  
  var g = fib();  
  for (var i = 0; i < 10; i++) {  
    document.write(g.next() + "<br>\n");  
  }  

INTERFACE ^

INSTANCE METHODS

next

Retrieve the next value.

syntax highlighting: