Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 標準組み込みオブジェクト
  5. GeneratorFunction

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

GeneratorFunction

Baseline Widely available

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 はグローバルオブジェクトではないことに注意してください。次のコードを評価することによって得ることができます。

js
const GeneratorFunction = function* () {}.constructor;

GeneratorFunctionFunction のサブクラスです。

試してみましょう

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.constructor

インスタンスオブジェクトを作成するコンストラクター関数です。GeneratorFunction インスタンスの場合、初期値はGeneratorFunction コンストラクターです。

GeneratorFunction.prototype.prototype

すべてジェネレーター関数は、同じprototype プロパティを共有しており、これはGenerator.prototype です。function* 構文またはGeneratorFunction() コンストラクターで生成されたそれぞれのジェネレーター関数も、自身のprototype プロパティを保有しています。このプロパティのプロトタイプはGeneratorFunction.prototype.prototype です。ジェネレーター関数が呼び出されると、そのprototype プロパティが返されるジェネレータオブジェクトのプロトタイプとなります。

GeneratorFunction.prototype[Symbol.toStringTag]

[Symbol.toStringTag] プロパティの初期値は文字列"GeneratorFunction" です。このプロパティはObject.prototype.toString() で使用されています。

これらのプロパティは、それぞれのGeneratorFunctionインスタンスが自分自身で持っているプロパティです。

prototype

関数がnew 演算子と共にコンストラクターとして使用される場合に使用されます。新しいオブジェクトのプロトタイプとなります。

インスタンスメソッド

親であるFunction から継承したメソッドがあります

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-generatorfunction-objects

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp