带括号的Javascript const声明 [英] Javascript const declaration with braces

查看:121
本文介绍了带括号的Javascript const声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

电子文档(例如 http://electron.atom.io/docs/ api / browser-window / )表示要使用解构语句导入某些功能:

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')

在Electron中运行代码时有效,但是Jasmine和Visual Studio *声明

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

正确的用法是什么?

*代码为实际使用Typescript编写(针对ES2015的版本为1.8),但在这种情况下,JS中的转译代码是相同的。

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

推荐答案

此代码有效ES6 / ES2015,但不是有效的ES5。

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

node.js> =支持解构分配 6.4 。如果您的Jasmine使用旧版本运行,它将无法正常工作。不确定是否使用Visual Studio,但是您似乎需要使用VS 2015的最新版本才能具有ES6功能。

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.

因此,您应该更新自己的工具,或者只需配置Typescript即可将其定位到ES5。

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

这篇关于带括号的Javascript const声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆