Ecmascript 6 features found in Chrome 38

We have an array with a number of properties on each page. Sometimes it has the "values" property. We will look at this with myArrayObject['values'] and expect either a string or undefined. After upgrading to Chrome 38, myArrayObject['values'] returns function values() { [native code] }

After some digging, this seems to be tied to the V8 ticket to implement @@ unscopables for the 6th edition of ecmascript . These changes were made two months ago. Shortly after one developer tried to push them back with a note saying they were "web breaking . "

So the question is, is Array.values ​​() an undocumented function, early adoption of the ecmascript-6 project, an error, or something else? Will it be a rollback? What other upcoming changes should I know?

A small example in Chrome 38.0.2125.101 (on Win7 64):

 var test=new Array(); // items pushed and popped ... // test['values'] may have been set at some point test['values']; //returns a function pointer: function values() { [native code] }. // yesterday this returned undefined 

edit: From Bergi's answer, it looks like ES6.

Will more ES6 features appear in background patches a few months before the spec is released? Is there anything I can do to protect our platform? Is there any way to request compatibility mode with ES5?

+6
source share
3 answers

Yes, Array.prototype.values comes from the ES6 project. This is a method that returns an iterator for the values ​​of an array.

If you want to store values ​​in an array that are not indexed numerically, you should not use Array , but a simple object (or in ES6, a Map ).

+6
source

The correction, @@ unscopables never rolled back from V8 - the second change you are referring to was just prepared for an emergency, but, fortunately, we did not need it, it never happened. So, @@ unscopables sends to Chrome 38, and accordingly, also Array.prototype.values.

It is impossible to disable ES6 functions, because it will not be very promising, and the code that relies on it will be doomed to loosen after a few months or in other browsers anyway.

The ES committee is usually very careful not to "break the web." In practice, this means that no actual use cases should be interrupted, i.e. Things that are already found on the Internet. Strictly speaking, any change violates some hypothetical code, because even completely new functions will noticeably change the behavior of "eval". If we avoided even a strict criterion, then language could never have developed.

Your specific example is not found in the wild, as far as I can tell. As others answered, in this case there is no reason to use arrays, [] -syntax works just as well with regular objects. You only need arrays when your indices are integers.

The only web development issues that have previously appeared with the new Array.prototype.values ​​method are related to the "with" construct (which you should not use, ever). Then @@ unscopables was introduced to get around this.

Edit: .values had to be removed again from V8 due to a bug in Microsoft OWA 2013. But think that this is a temporary measure. Microsoft is aware of the problem and .values will be back as soon as possible.

+2
source

Google Chrome 38.0.2125.111 is no longer implemented by Array.prototype.values .

This little test

 var myArray = new Array(); alert(myArray['values']); alert(myArray['anotherparameter']); 

returns undefined for both warnings.

However, the hasOwnProperty method can be used to determine if an array has a property named values or not:

 var myArray = new Array(); alert(myArray.hasOwnProperty('values')); // alert false myArray['values'] = "Hello"; alert(myArray.hasOwnProperty('values')); // alert true 

this works for browsers implementing Array.prototype.values such as Opera 25.0.1614.63

+1
source

Source: https://habr.com/ru/post/976529/


All Articles