Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created March 13, 2011 18:12
Show Gist options
  • Save joseanpg/868301 to your computer and use it in GitHub Desktop.
Save joseanpg/868301 to your computer and use it in GitHub Desktop.
About Mozilla Generators
//script type="application/javascript;version=1.7"
function FactorGenMaker(factor) {
let(j=1){for(;;) yield factor*j++};
}
function NullGenMaker() {
for(;;) yield null;
}
let (positiveEven = FactorGenMaker(2),
negativeEven = FactorGenMaker(-2),
nuller = NullGenMaker()) {
console.log('First positiveEven number is 2');
try {console.log(positiveEven.next.call({})+', if this is an Object');} catch (e) {console.log(e)}
console.log(positiveEven.next.call(nuller)+', if this is a generator of other class');
console.log(positiveEven.next.call(negativeEven)+', if this is other generator of the same class');
console.log(positiveEven.next.call(positiveEven)+', if this is this');
console.log('[[Class]]:'+/\[object (.*)\]/.exec(Object.prototype.toString.call(positiveEven))[1]);
}
/**
Output
------
First positiveEven number is 2
TypeError: Generator.prototype.next called on incompatible Object { message="Generator.prototype.nex... on incompatible Object", more...}
null, if this is a generator of other class
-2, if this is other generator of the same class
2, if this is this
[[Class]]:Generator
Therefore
---------
This is the generator object which internal resumable-function will be called.
Exists the Generator Class
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment