简体   繁体   English

为什么可以在React Native中使用解构赋值?

[英]why it possible to use destructuring assignment in React Native?

In the example of react native tutorial , I find syntax which is defined in ECMAScript 2015 (ES6) standard called Destructuring assignment. 在本机教程的示例中,我找到了ECMAScript 2015(ES6)标准中定义的语法,该标准称为Destructuring assignment。 But as I know, iojs and nodejs do not support this syntax. 但据我所知,iojs和nodejs不支持这种语法。 How can I use it in React Native? 如何在React Native中使用它?

You are right nodejs and iojs do not support ES6 syntax. 你是对的nodejs和iojs不支持ES6语法。 But react native: 但反应原生:

As of version 0.5.0, React Native ships with the Babel JavaScript compiler. 从版本0.5.0开始,React Native附带了Babel JavaScript编译器。

Read more here 在这里阅读更多

That means that there is another transpiler ( Babel ) at work in the React packager. 这意味着在React打包器中有另一个转换器( Babel )正在工作。 It converts from ECMAScript 2015 (ES6) to ES5. 它从ECMAScript 2015(ES6)转换为ES5。 This allows you to use the ES6 features like: destructuring, computed property keys, classes, arrow functions, block-scoped variables and more. 这允许您使用ES6功能,例如:解构,计算属性键,类,箭头函数,块范围变量等。

If you want to use those features in the React (not Native) app, you will need to include Babel in your project. 如果要在React(非Native)应用程序中使用这些功能,则需要在项目中包含Babel。


Edit: 编辑:

There is no another transpiler. 没有其他的转换器。

React and React Native have both switched their respective build systems to make use of Babel . React和React Native都将各自的构建系统切换为使用Babel This replaced JSTransform , the source transformation tool that we wrote at Facebook. 这取代了我们在Facebook上编写的源转换工具JSTransform

More in Deprecating JSTransform and react-tools 更多有关弃用JSTransform和react-tools的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM