Skip to content

Conversation

@cow1337killer3
Copy link
Contributor

In JavaScript, all non-Symbol property key values (including index numbers) are converted to Strings, so there is no way for the language to differentiate between collection[1] and collection["1"]. That means that namedItem and computed property access cannot be equivalent since namedItem doesn't return elements by index while computed property access does.

Description

Motivation

Additional details

Related issues and pull requests

In JavaScript, all non-Symbol property key values (including index numbers) are converted to Strings, so there is no way for the language to differentiate between `collection[1]` and `collection["1"]`. That means that `namedItem` and computed property access cannot be equivalent since `namedItem` doesn't return elements by index while computed property access does.
@cow1337killer3 cow1337killer3 requested a review from a team as a code owner August 29, 2024 16:06
@cow1337killer3 cow1337killer3 requested review from Elchi3 and removed request for a team August 29, 2024 16:06
@github-actions github-actions bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Aug 29, 2024
@Josh-Cena
Copy link
Member

"Using bracket access" is not always replaceable with "using namedItem", but the reverse is true, does that make sense? I think we should keep mentioning that "you can replace collection.namedItem("value") with just collection["value"]".

@Josh-Cena Josh-Cena added the awaiting response Awaiting for author to address review/feedback label Sep 1, 2024
@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Sep 5, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2024

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.

I noticed a few other things that are non-conventional on this page, so I've updated them myself. Thanks for the update; the idea is correct.

@Josh-Cena Josh-Cena changed the title Remove incorrect information about HTMLCollection Reword HTMLCollection.namedItem replacement Sep 5, 2024
@Josh-Cena Josh-Cena merged commit 13a3c24 into mdn:main Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting response Awaiting for author to address review/feedback Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants