2017-05-06 103 views
0

問:有誰知道這個JavaScript ES6功能被稱爲什麼?這是將一個前綴應用於識別的名稱的技術。像這樣:JavaScript ES6:這個功能稱爲什麼?

var { Router, 
Route, 
IndexRoute, 
IndexLink, 
hashHistory, 
Link } = ReactRouter; 

這節省了我不得不寫的長代碼。例如:

我在寫這個陣營:

<Route path="/acc"   component={CLAccounts} /> 
<Route path="/acc/:year"  component={CLAccounts} /> 
<Route path="/acc/:year/:month"  component={CLAccounts} /> 

取而代之的是:

<ReactRouterRoute path="/acc"   component={CLAccounts} /> 
<ReactRouterRoute path="/acc/:year"  component={CLAccounts} /> 
<ReactRouterRoute path="/acc/:year/:month" component={CLAccounts} /> 
+0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment – Mottie

+1

這有什麼好做 「前綴」。正確的「long」語法是「ReactRouter.Route」(不是'ReactRouterRoute'),它是簡單的屬性訪問。 – Bergi

+0

這篇文章明確地說明了如何保存輸入。即:加前綴。 也許它只是以不同的方式使用語法。 –

回答

0

這就是所謂的解構。這是超級有用的!

更多here

+0

謝謝。解構似乎更多的是將一個數組分解成單獨的變量。這裏本身沒有數據,只是一種前綴變量的方式。無論如何,保存輸入非常有用。 –