Javascript对象括号表示法({Navigation} =)在左侧的分配 [英] Javascript object bracket notation ({ Navigation } =) on left side of assign
问题描述
我以前没有看到这个语法,我想知道这是什么。左侧的方括号引起了语法错误:unexpected token {
I haven't seen this syntax before and am wondering what it's all about. The brackets on the left are throwing a syntax error: "unexpected token {"
var { Navigation } = require('react-router');
我不知道webpack配置的哪个部分正在转换,语法的目的是什么。这是和谐的事吗?有人可以启发我吗?
I'm not sure what part of the webpack config is transforming or what the purpose of the syntax is. Is it a Harmony thing? Can someone enlighten me?
推荐答案
解构赋值语法是一个JavaScript表达式,
使得可以从数组或对象中使用
语法反映了数组和对象文字的构造。
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.
资料来源: 在MDN上结构化作业参考
对象解构
Object destructuring
var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true
// Assign new variable names
var {p: foo, q: bar} = o;
console.log(foo); // 42
console.log(bar); // true
数组解构
Array destructuring
var foo = ["one", "two", "three"];
// without destructuring
var one = foo[0];
var two = foo[1];
var three = foo[2];
// with destructuring
var [one, two, three] = foo;
这篇关于Javascript对象括号表示法({Navigation} =)在左侧的分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!