javascript - Chrome 无法进行数组解构

标签 javascript google-chrome destructuring

我有以下功能:

function evaluateScroll(positions, width){
    var scale = width / (width - Math.abs(positions[0]) - Math.abs(positions[1]));
    var startLocation = positions[0] / width;

    return [scale, startLocation];
}

我按以下方式使用它:

[tscale, tstartLocation] = evaluateScroll(scrollPositions, scrollPlotWidth);

在 Safari 和 Firefox 中,它的工作方式与预期的工作方式相同。然而,在 Chrome 中,代码在这一行挂起。

将其更改为:

var holder = evaluateScroll(scrollPositions, scrollPlotWidth);

可以工作,但是我必须将 holder 的索引解析为适当的变量。

为什么 Chrome 无法使用数组样式赋值?我是否可以实现一种适用于所有浏览器的语法,而无需执行holder变量并重新分配给适当的浏览器?

最佳答案

chrome 48(当前稳定版)似乎还不支持解构赋值语法:https://kangax.github.io/compat-table/es6/#destructuring

看起来 49+ 就很好了!

关于javascript - Chrome 无法进行数组解构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35234689/

相关文章:

使用 Chrome 的 CSS 背景线性渐变错误?

Javascript解构并分配给新对象

javascript - 使用 Object.create() 将函数与原型(prototype)上的属性合并

javascript - Chrome VM 文件重复 javascript

javascript - 如何区分 Fedora 和 Ubuntu?

google-chrome - 使用用户代理获取许多请求 [Mozilla/5.0]

vector - 向量的解构

javascript - 是否可以重构普通 JS DOM 操作

javascript - 我的 Google 饼图中未对齐的标签/切片文本

javascript - 从 MySQL 中的 TinyMCE 数据中删除/r/n 标签