Closed
Bug 1263681
Opened 9 years ago
Closed 9 years ago
Simple example for ES6 Generator function is misleading
Categories
(Developer Documentation Graveyard :: JavaScript, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: satbirjhuti, Unassigned)
References
()
Details
:: Developer Documentation Request
Request Type: Correction
Gecko Version: unspecified
Technical Contact:
:: Details
The comment right after the last console.log suggests the output should be `undefined`. Whereas in reality the output is `3`
Actual:
```
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // undefined
```
Expected:
```
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
```
Reporter | ||
Updated•9 years ago
|
In the example, there is a condition to stop the generator before reaching 3.
If you inspect the result of gen.next(), you should normally have the following:
gen.next(); // Object { value: 0, done: false }
gen.next(); // Object { value: 1, done: false }
gen.next(); // Object { value: 2, done: false }
gen.next(); // Object { value: undefined, done: true }
In other words, when the generator has reached its final state (when "done" is true), the "value" property doesn't matter anymore and should be undefined (according to https://tc39.github.io/ecma262/2016/#sec-iteratorresult-interface).
Do you think of a better wording for the example?
Flags: needinfo?(satbirjhuti)
Reporter | ||
Comment 2•9 years ago
|
||
Missed that conditional! This bug is invalid. Closing it.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Flags: needinfo?(satbirjhuti)
Resolution: --- → INVALID
Updated•9 years ago
|
Keywords: dev-doc-needed,
doc-bug-filed,
user-doc-needed
Priority: P4 → --
You need to log in
before you can comment on or make changes to this bug.
Description
•