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

Wrong historical fact in Symbol.unscopables page #34639

Closed
witch-factory opened this issue Jul 5, 2024 · 1 comment · Fixed by #34646
Closed

Wrong historical fact in Symbol.unscopables page #34639

witch-factory opened this issue Jul 5, 2024 · 1 comment · Fixed by #34646
Labels
accepting PR Feel free to open a PR to resolve this issue Content:JS JavaScript docs

Comments

@witch-factory
Copy link
Contributor

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables

What specific section or headline is this issue about?

Scoping in with statements

What information was incorrect, unhelpful, or incomplete?

The document says, in summary, "@@unscopables symbol was introduced because Array.prototype.keys() method was introduced in ECMAScript 2015 and later." But the reason why @@unscopables was introduced was Array.prototype.values(), not keys().

It is true that keys() was one of the first elements included when @@unscopables was introduced. However, this was not because keys() caused any issues, but because keys(), values(), and entries() were grouped together as methods. The introduction of @@unscopables was due to the ExtJS framework using the code with(values), which conflicted with the new Array.prototype.values().

What did you expect to see?

I suggest, in the "Scoping in with statements" section, chaning the Array.prototype.keys() to Array.prototype.values() and adding some comments in the example code something like this.

The following code works fine in ES5 and below. However, in ECMAScript 2015 and later, the [Array.prototype.values()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys) method was introduced. That means that inside a with environment, "values" would now be the method and not the variable. That's why the @@unscopables symbol was introduced. A built-in @@unscopables setting is implemented as [Array.prototype[@@unscopables]](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@unscopables) to prevent some of the Array methods being scoped into the with statement.

var values = [];

with (Array.prototype) {
  // If @@unscopables did not exist, values would become Array.prototype.values, 
  // and an error would have occurred.
  values.push("something");
}

Do you have any supporting links, references, or citations?

In 2013-06, there came bug reports in firefox 24 which introduced Array.prototype.values. bug report 1 bug report 2

So in the 2013-07 TC39 meeting, Dave Herman suggested a blacklist for with, named "@@unscopable". meeting note link This became an @@unscopables nowadays.

And a simple explanation in Exploring ES6

Do you have anything more you want to share?

If it’s alright, may I proceed with making the PR?

MDN metadata

Page report details
@witch-factory witch-factory added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jul 5, 2024
@github-actions github-actions bot added the Content:JS JavaScript docs label Jul 5, 2024
@Josh-Cena Josh-Cena added accepting PR Feel free to open a PR to resolve this issue and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Jul 5, 2024
@Josh-Cena
Copy link
Member

Sure, sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting PR Feel free to open a PR to resolve this issue Content:JS JavaScript docs
2 participants