mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
8.97k stars 22.45k forks source link

Wrong historical fact in Symbol.unscopables page #34639

Closed witch-factory closed 17 hours ago

witch-factory commented 3 days ago

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 * Folder: `en-us/web/javascript/reference/global_objects/symbol/unscopables` * MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/global_objects/symbol/unscopables/index.md * Last commit: https://github.com/mdn/content/commit/fb85334ffa4a2c88d209b1074909bee0e0abd57a * Document last modified: 2023-09-25T07:33:31.000Z
Josh-Cena commented 3 days ago

Sure, sounds good to me!