I am exploring new features introduced in Javascript 1.7. In generators, I came across the following code and could not understand the difference an asterisk (*) would make to the function declaration. Link : https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7#Generators
With asterisk, JSFiddle
Only Firefox supports Javascript 1.7. Open this fiddle in Firefox
function *fib(){
var i=0,j=1;
while(true){
yield i;
var t=i;
i=j;
j+=t;
}
}
var g=fib();
console.log(g.next().value);//0
console.log(g.next().value);//1
console.log(g.next().value);//1
Without asterisk,
function fib(){
var i=0,j=1;
while(true){
yield i;
var t=i;
i=j;
j+=t;
}
}
var g=fib();
console.log(g.next().value);//undefined
console.log(g.next().value);//undefined
console.log(g.next().value);//undefined