简体   繁体   中英

Chrome is unable to do array destructuring

I have the following function:

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

    return [scale, startLocation];
}

and I use it in the following way:

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

In Safari and Firefox, it works as it would be expected to work. In Chrome, however, the code hangs-up at this line.

Changing it to:

var holder = evaluateScroll(scrollPositions, scrollPlotWidth);

works, but then I have to parse out the indexes of holder to the appropriate variables.

How come Chrome won't work with the array-style assignment? Is there a syntax that I can implement that would work across all browsers, without having to do the holder variable and reassigning to the appropriate ones?

It appears chrome 48 (current stable) does not support the destructuring assignment syntax yet: https://kangax.github.io/compat-table/es6/#destructuring

Looks like it's good in 49+ though!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM