gpt4 book ai didi

javascript - Chrome 38 中的 ecmascript 6 特性

转载 作者:数据小太阳 更新时间:2023-10-29 05:10:10 24 4
gpt4 key购买 nike

我们有一个数组,每个页面上都有许多属性。有时它有一个“值”属性。我们使用 myArrayObject['values'] 检查它并期望是字符串或未定义。更新到 Chrome 38 后 myArrayObject['values'] 返回 function values() { [native code] }

经过一番挖掘,这似乎与 V8 ticket 有关实现@@unscopables for the 6th Edition of ecmascript .这些变化是 committed两个月前。不久后,一名开发人员试图 roll them back with the note that they were "web-breaking" .

所以问题是,Array.values() 是未记录的功能、早期采用的 ecmascript-6 草案、错误还是其他?这会被回滚吗?我还应该注意哪些其他即将发生的变化?

Chrome 38.0.2125.101(在 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

编辑:从 Bergi 的回答来看,这看起来像是 ES6 功能。

在规范发布前几个月,是否会有更多 ES6 特性出现在后台补丁中?我可以做些什么来保护我们的平台?有什么方法可以请求 ES5 兼容模式吗?

最佳答案

是的,Array.prototype.values来自 ES6 草案。它是一种为您返回数组值的迭代器的方法。

如果你想在你的数组中存储没有数字索引的值,你不应该使用 Array 而应该使用一个普通对象(或者,在 ES6 中,一个 Map ).

关于javascript - Chrome 38 中的 ecmascript 6 特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26288549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com