Showing posts with label asterisk. Show all posts
Showing posts with label asterisk. Show all posts

Thursday, May 10, 2012

function* in JavaScript


In this page I found a new JavaScript function type:




// NOTE: "function*" is not supported yet in Firefox.
// Remove the asterisk in order for this code to work in Firefox 13

function* fibonacci() { // !!! this is the interesting line !!!
let [prev, curr] = [0, 1];
for (;;) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}