Skip to content

Instantly share code, notes, and snippets.

@vldvel
Created March 2, 2018 10:21
Show Gist options
  • Save vldvel/54a532b737e5491e7d77b0ccae988d5e to your computer and use it in GitHub Desktop.
Save vldvel/54a532b737e5491e7d77b0ccae988d5e to your computer and use it in GitHub Desktop.
function * generator() {
yield 1;
}
generator.prototype.__proto__; // Generator {constructor: GeneratorFunction, next: ƒ, return: ƒ, throw: ƒ, Symbol(Symbol.toStringTag): "Generator"}
// as Generator is not global variable we have to write something like this
generator.prototype.__proto__.math = function(e = 0) {
return e * Math.PI;
}
generator.prototype.__proto__; // Generator {math: ƒ, constructor: GeneratorFunction, next: ƒ, return: ƒ, throw: ƒ, …}
const gen = generator();
gen.math(1); // 3.141592653589793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment