Chrome无法进行阵列解构

时间:2016-02-05 22:32:08

标签: 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无法使用阵列式分配?是否有一种我可以实现的语法可以在所有浏览器中使用,而无需执行持有者变量并重新分配给适当的变量?

2 个答案:

答案 0 :(得分:3)

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

虽然看起来好像是49+!

答案 1 :(得分:1)

我建议您使用Babel编写现代ES6 / 7 Javascript代码。