Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
80 lines (55 loc) · 3.31 KB
/
Copy pathindex.md
File metadata and controls
80 lines (55 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: GeneratorFunction
slug: Web/JavaScript/Reference/Global_Objects/GeneratorFunction
l10n:
sourceCommit: 544b843570cb08d1474cfc5ec03ffb9f4edc0166
---
Das **`GeneratorFunction`** Objekt bietet Methoden für [Generatorfunktionen](/de/docs/Web/JavaScript/Reference/Statements/function*). In JavaScript ist jede Generatorfunktion tatsächlich ein `GeneratorFunction` Objekt.
Beachten Sie, dass `GeneratorFunction` _kein_ globales Objekt ist. Es kann mit dem folgenden Code erhalten werden:
```js
const GeneratorFunction = function* () {}.constructor;
```
`GeneratorFunction` ist eine Unterklasse von {{jsxref("Function")}}.
{{InteractiveExample("JavaScript Demo: GeneratorFunction", "taller")}}
```js interactive-example
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);
// Expected output: "abc"
```
## Konstruktor
- {{jsxref("GeneratorFunction/GeneratorFunction", "GeneratorFunction()")}}
- : Erstellt ein neues `GeneratorFunction` Objekt.
## Instanz-Eigenschaften
_Erbt auch Instanz-Eigenschaften von seinem Elternteil {{jsxref("Function")}}_.
Diese Eigenschaften sind auf `GeneratorFunction.prototype` definiert und werden von allen `GeneratorFunction` Instanzen geteilt.
- {{jsxref("Object/constructor", "GeneratorFunction.prototype.constructor")}}
- : Die Konstruktorfunktion, die das Instanzobjekt erstellt hat. Für `GeneratorFunction` Instanzen ist der Anfangswert der {{jsxref("GeneratorFunction/GeneratorFunction", "GeneratorFunction")}} Konstruktor.
- {{jsxref("GeneratorFunction.prototype.prototype")}}
- : Alle Generatorfunktionen teilen die gleiche [`prototype`](/de/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype) Eigenschaft, die [`Generator.prototype`](/de/docs/Web/JavaScript/Reference/Global_Objects/Generator) ist. Jede mit der `function*` Syntax oder dem `GeneratorFunction()` Konstruktor erstellte Generatorfunktion hat ebenfalls eine eigene `prototype` Eigenschaft, deren Prototyp `GeneratorFunction.prototype.prototype` ist. Wenn die Generatorfunktion aufgerufen wird, wird ihre `prototype` Eigenschaft zum Prototyp des zurückgegebenen Generatorobjekts.
- `GeneratorFunction.prototype[Symbol.toStringTag]`
- : Der Anfangswert der [`[Symbol.toStringTag]`](/de/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) Eigenschaft ist der String `"GeneratorFunction"`. Diese Eigenschaft wird in {{jsxref("Object.prototype.toString()")}} verwendet.
Diese Eigenschaften sind Eigeneigenschaften jeder `GeneratorFunction` Instanz.
- {{jsxref("GeneratorFunction/prototype", "prototype")}}
- : Wird verwendet, wenn die Funktion als Konstruktor mit dem [`new`](/de/docs/Web/JavaScript/Reference/Operators/new) Operator verwendet wird. Es wird zum Prototyp des neuen Objekts.
## Instanz-Methoden
_Erbt Instanz-Methoden von seinem Elternteil {{jsxref("Function")}}_.
## Spezifikationen
{{Specifications}}
## Browser-Kompatibilität
{{Compat}}
## Siehe auch
- [`function*`](/de/docs/Web/JavaScript/Reference/Statements/function*)
- [`function*` Ausdruck](/de/docs/Web/JavaScript/Reference/Operators/function*)
- {{jsxref("Function")}}
- {{jsxref("AsyncFunction")}}
- {{jsxref("AsyncGeneratorFunction")}}
- {{jsxref("Functions", "Funktionen", "", 1)}}