Javascript object bracket notation ({ Navigation } =) on left side of assign

后端 未结 4 775
梦谈多话
梦谈多话 2020-11-21 05:53

I haven\'t seen this syntax before and am wondering what it\'s all about.

var { Navigation } = require(\'react-router\');

The brackets on

4条回答
  •  广开言路
    2020-11-21 06:41

    This is destructuring assignment. It's a new feature of ECMAScript 2015.

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

    Is the equivalent to:

    var AppRegistry = React.AppRegistry;
    var StyleSheet = React.StyleSheet;
    var Text = React.Text;
    var View = React.View;
    

提交回复
热议问题