Created
March 13, 2011 18:12
-
-
Save joseanpg/868301 to your computer and use it in GitHub Desktop.
About Mozilla Generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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