在需要之后,在本机示例中发生了什么?

时间:2022-08-22 20:34:12

I find the following code in react native tutorial,

我在react本机教程中找到以下代码,

 var {
      AppRegistry,
      Image,
      StyleSheet,
      Text,
      View,
    } = React;

and it seems like parallel assignment in Python to me. But I can not run it by nodejs:

它看起来像Python中的并行赋值给我。但我无法通过nodejs运行它:

var dict = {a: "19", b: "20"};
var {
    a,
    b
    }
    = dict;

console.log(a);
console.log(b);

so I am wondering if this syntax is only valid in React native or it is supported by nodejs?

所以我想知道这种语法是否仅在React本机中有效或者是否由nodejs支持?

1 个解决方案

#1


0  

This is an ES6 (ES2015) Destructuring statement.

这是ES6(ES2015)解构声明。

https://babeljs.io/docs/learn-es2015/#destructuring

React Native uses Babel by default for transformation and Destructuring is one of the things enabled by default.

React Native默认使用Babel进行转换,Destructuring是默认情况下启用的功能之一。

#1


0  

This is an ES6 (ES2015) Destructuring statement.

这是ES6(ES2015)解构声明。

https://babeljs.io/docs/learn-es2015/#destructuring

React Native uses Babel by default for transformation and Destructuring is one of the things enabled by default.

React Native默认使用Babel进行转换,Destructuring是默认情况下启用的功能之一。