你如何在react-native中声明'const'?

时间:2015-07-31 15:47:30

标签: ios reactjs react-native

我一直收到错误SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

我认为这是因为我有这样一句话:

    const shouldSet = touches.length === 1;
    if (shouldSet) {
      const { onPanBegin } = this.props;

3 个答案:

答案 0 :(得分:3)

Update 2015-10-23: as of React Native v0.13.0-rc const is now enabled.

React Native's JavaScript environment is not a browser, instead it uses JavaScriptCore. Anything that isn't supported natively needs to be transformed down to a subset of JS that JavaScriptCore supports, and React Native uses Babel to do that. Here are the transformations that React Native uses (as of 2015-07-31):

ES5

  • Reserved Words: promise.catch(function() { });

ES6

  • Arrow functions
  • Call spread
  • Classes
  • Destructuring
  • Computed Properties
  • Object Consise Method
  • Object Short Notation
  • Rest Params
  • Template Literals:

ES7

  • Object Spread
  • Function Trailing Comma

It is not immediately clear to me why constants aren't included in this list, and it appears that support for overriding it still isn't quite ready:

https://github.com/facebook/react-native/issues/1451

答案 1 :(得分:0)

目前在react-native android中不支持<input type="button" onclick="location.href='@Url.Action("MyAction", "MyController", new {})' + '?' + 'newSurname='+getSelectedVersion()"/> 关键字,我希望它能在下一版本的react-native中使用。修复是微不足道的,有关详细信息,请查看原点github issue

答案 2 :(得分:0)

你需要得到最新版本的react-native。

pod&#39; React&#39;,&#39; 0.13.0-rc&#39;