Javascript const declaration with braces

谁说胖子不能爱 提交于 2019-12-11 08:03:00

问题


Electron's documentation (for example http://electron.atom.io/docs/api/browser-window/) says to import some features using a destructuring statement:

const {BrowserWindow} = require('electron')

This works when running the code in Electron but Jasmine and Visual Studio* claim that the "{" is a syntax error.

What is the correct usage?

*The code is actually written in Typescript (1.8 targeting ES2015) but the transpiled code in JS is identical in this case.


回答1:


This code is valid ES6/ES2015, but is not valid ES5.

Destructuring assignments are supported in node.js >= 6.4. If your Jasmine is run with an older version, it will not work. Not sure about Visual Studio, but it looks like you need a recent version of VS 2015 to be able to have ES6 features.

Therefore you should either update your tools, or just configure Typescript so it targets ES5 instead.



来源:https://stackoverflow.com/questions/39035638/javascript-const-declaration-with-braces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!