P粉5783439942023-08-25 10:55:29
这是解构赋值。它是ECMAScript 2015的一个新特性。
var { AppRegistry, StyleSheet, Text, View, } = React;
等同于:
var AppRegistry = React.AppRegistry; var StyleSheet = React.StyleSheet; var Text = React.Text; var View = React.View;
P粉3500367832023-08-25 10:49:56
var o = {p: 42, q: true}; var {p, q} = o; console.log(p); // 42 console.log(q); // true // 分配新的变量名 var {p: foo, q: bar} = o; console.log(foo); // 42 console.log(bar); // true
var foo = ["one", "two", "three"]; // 不使用解构 var one = foo[0]; var two = foo[1]; var three = foo[2]; // 使用解构 var [one, two, three] = foo;