Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify usage of return values in iterator protocol #37511

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

etrepum
Copy link
Contributor

@etrepum etrepum commented Jan 6, 2025

Description

There's an example with an iterable that returns an iterator that enumerates 1, 2, and returns with {done: true, value: 3}, and is evaluated with const [b, c, d] = obj.

It takes a careful reading to notice that the third value is used only to ensure that the iterator is exhausted and that the value from the iterator return is not bound to d.

Motivation

Since the example is "Returning 3" in the comment above when next() returns {done:true, value: 3} a reader may think that 3 is bound to d in this case. With this comment, it will be easier to see that the value returned by an exhausted iterator is not used in any normal scenario, including array destructuring.

Additional details

N/A

Related issues and pull requests

N/A

There's an example with an iterable that returns an iterator that enumerates 1, 2, and returns with `{done: true, value: 3}`, and is evaluated with `const [b, c, d] = obj`.

It takes a careful reading to notice that the third value is used only to ensure that the iterator is exhausted and that the value from the iterator return is not bound to `d`.
@etrepum etrepum requested a review from a team as a code owner January 6, 2025 06:48
@etrepum etrepum requested review from Josh-Cena and removed request for a team January 6, 2025 06:48
@github-actions github-actions bot added Content:JS JavaScript docs size/xs [PR only] 0-5 LoC changed labels Jan 6, 2025
Copy link
Contributor

github-actions bot commented Jan 6, 2025

Preview URLs

Flaws (6)

URL: /en-US/docs/Web/JavaScript/Reference/Iteration_protocols
Title: Iteration protocols
Flaw count: 6

  • macros:
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/JavaScript/First_steps
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/JavaScript/Building_blocks
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/JavaScript/Objects
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks
    • and 1 more flaws omitted

(comment last updated: 2025-01-06 16:47:41)

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Josh-Cena Josh-Cena merged commit 21916b1 into mdn:main Jan 6, 2025
8 checks passed
@etrepum etrepum deleted the patch-1 branch January 6, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs size/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants