简体   繁体   中英

Destructuring statement in chrome/chromium 44 not being recognised

As far as I know, this is valid EcmaScript6:

let obj = {foo: "foo", bar: "bar"}; 
let {foo, bar} = obj; // <- Syntax error here

Firefox runs this code just fine, but both Google Chrome and Chromium give me this error:

Uncaught SyntaxError: Unexpected token {

I know in firefox, scripts tags have to be flagged with "version=1.7" in the type attribute for this to work, but in Google Chrome this results in the script getting ignored. A normal script tag gives this error.

Does this mean this feature is not implemented in Google Chrome? Or am I missing something?

That's right. Currently, it isn't supported yet.

https://devdocs.io/javascript/operators/destructuring_assignment

Although Chrome doesn't support some new features of ES6 (check this table to see what is already supported on different browsers), you can use a polyfill/plugins to enable certain features on Chrome. You can find polyfill and plugins on Babel . Just read through the plugins documentation and implement the ones you want.

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