You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 1bug 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.
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
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 becauseArray.prototype.keys()
method was introduced in ECMAScript 2015 and later." But the reason why@@unscopables
was introduced wasArray.prototype.values()
, notkeys()
.It is true that
keys()
was one of the first elements included when@@unscopables
was introduced. However, this was not becausekeys()
caused any issues, but becausekeys()
,values()
, andentries()
were grouped together as methods. The introduction of@@unscopables
was due to the ExtJS framework using the codewith(values)
, which conflicted with the newArray.prototype.values()
.What did you expect to see?
I suggest, in the "Scoping in with statements" section, chaning the
Array.prototype.keys()
toArray.prototype.values()
and adding some comments in the example code something like this.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
en-us/web/javascript/reference/global_objects/symbol/unscopables
The text was updated successfully, but these errors were encountered: