4
我想在es6上定义一个数组,我得到Use of future reserved word in strict mode
。这是我的尝试:在严格模式下使用未来的保留字
{let colours = ["green","yellow","red"]}
可能是什么原因?
我想在es6上定义一个数组,我得到Use of future reserved word in strict mode
。这是我的尝试:在严格模式下使用未来的保留字
{let colours = ["green","yellow","red"]}
可能是什么原因?
使用let
是什么导致严格模式内的错误。将其更改为var
。听起来像你在es2015 env。或者你可以用babel之类的东西来编译你的代码。
您也不能在.jsx表达式中定义变量。在return语句之外定义数组,并在表达式中引用它:let colours = ["green","yellow","red"]
,然后在{ colours }
之后。
你为什么在它周围有花括号? – Carcigenicate
我有大括号,因为我试图在reactJS文件中定义数组 –
您不能在'.jsx'表达式中定义变量。在return语句之外定义数组,并在表达式中引用它:'let colors = [“green”,“yellow”,“red”]'然后是'{colors}'使用'let'就是导致严格模式内的错误。将其更改为'var'。听起来像你在es2015 env。或者你可以使用babel来传递代码:https://babeljs.io/ –