HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年9月.
GeneratorFunction オブジェクトは、ジェネレーター関数のメソッドを提供します。JavaScript では、すべてのジェネレーター関数は実際には GeneratorFunction オブジェクトです。
GeneratorFunction
GeneratorFunction はグローバルオブジェクトではないことに注意してください。次のコードを評価することによって得ることができます。
const GeneratorFunction = function* () {}.constructor;
GeneratorFunction は Function のサブクラスです。
Function
const GeneratorFunction = function* () {}.constructor; const foo = new GeneratorFunction(` yield 'a'; yield 'b'; yield 'c'; `); let str = ""; for (const val of foo()) { str += val; } console.log(str); // 予想される結果: "abc"
GeneratorFunction()
新しい GeneratorFunction オブジェクトを生成します。
親である Function から継承したプロパティもあります。
これらのプロパティは GeneratorFunction.prototype で定義されており、すべての GeneratorFunction インスタンスで共有されます。
GeneratorFunction.prototype
GeneratorFunction.prototype.constructor
インスタンスオブジェクトを作成するコンストラクター関数です。GeneratorFunction インスタンスの場合、初期値は GeneratorFunction コンストラクターです。
GeneratorFunction.prototype.prototype
すべてジェネレーター関数は、同じ prototype プロパティを共有しており、これは Generator.prototype です。 function* 構文または GeneratorFunction() コンストラクターで生成されたそれぞれのジェネレーター関数も、自身の prototype プロパティを保有しています。このプロパティのプロトタイプは GeneratorFunction.prototype.prototype です。ジェネレーター関数が呼び出されると、その prototype プロパティが返されるジェネレータオブジェクトのプロトタイプとなります。
prototype
Generator.prototype
function*
GeneratorFunction.prototype[Symbol.toStringTag]
[Symbol.toStringTag] プロパティの初期値は文字列 "GeneratorFunction" です。このプロパティは Object.prototype.toString() で使用されています。
[Symbol.toStringTag]
"GeneratorFunction"
Object.prototype.toString()
これらのプロパティは、それぞれのGeneratorFunctionインスタンスが自分自身で持っているプロパティです。
関数が new 演算子と共にコンストラクターとして使用される場合に使用されます。新しいオブジェクトのプロトタイプとなります。
new
親である Function から継承したメソッドがあります。
Enable JavaScript to view this browser compatibility table.
AsyncFunction
AsyncGeneratorFunction