Square bracket notation for JavaScript objects: using assignment on the left ({ Navigation } =)
P粉964682904
2023-08-24 17:31:38
<p>I haven't seen this syntax before and would like to know what it means. </p>
<pre class="brush:php;toolbar:false;">var { Navigation } = require('react-router');</pre>
The curly brace on the left of <p> will cause a syntax error: </p>
<blockquote>
<p>unexpected token {</p>
</blockquote>
<p>I'm not sure which part of the webpack configuration does the conversion, or what the purpose of this syntax is. Is this a Harmony thing? Can someone explain this to me? </p>
This is destructuring assignment. It is a new feature of ECMAScript 2015.
Equivalent to:
It is called Destructuring assignment and is part of the ES2015 standard .
Object destructuring
Array destructuring