why it possible to use destructuring assignment in React Native?

故事扮演 提交于 2019-12-10 19:25:57

问题


In the example of react native tutorial, I find syntax which is defined in ECMAScript 2015 (ES6) standard called Destructuring assignment. But as I know, iojs and nodejs do not support this syntax. How can I use it in React Native?


回答1:


You are right nodejs and iojs do not support ES6 syntax. But react native:

As of version 0.5.0, React Native ships with the Babel JavaScript compiler.

Read more here

That means that there is another transpiler (Babel) at work in the React packager. It converts from ECMAScript 2015 (ES6) to ES5. This allows you to use the ES6 features like: destructuring, computed property keys, classes, arrow functions, block-scoped variables and more.

If you want to use those features in the React (not Native) app, you will need to include Babel in your project.


Edit:

There is no another transpiler.

React and React Native have both switched their respective build systems to make use of Babel. This replaced JSTransform, the source transformation tool that we wrote at Facebook.

More in Deprecating JSTransform and react-tools



来源:https://stackoverflow.com/questions/31900951/why-it-possible-to-use-destructuring-assignment-in-react-native

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