2017-10-06 4 views
0

私はタイスクリプトを学習しており、それについては非常に新しいです。現時点では、私は少し早く理解できるように、いくつかのプロジェクトのコードを読もうとしています。
[location.nlc, ...groups]とconst nlcの使用方法が混乱しています。typescriptの[location.nlc、... groups]の目的は何ですか?

groups=['b','c','d']; location.nlc="a";

次のコードは、ちょうど同じ値とキー 'A'、 'B'、 'C​​'、 'D' との辞書を作成しますと言います。私の推測は正しいですか?ここで

const groups = location.groups ? location.groups.split(",") : []; 
    const clusters: ClusterMap = {}; 
    for (const nlc of [location.nlc, ...groups]) { 
     clusters[nlc] = nlc; 
    } 
+0

新しいes6のオペレータと機能について読むことができます? – toskv

+0

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

答えて

1

は、注釈付きの例であり、いくつかのきちんとした活字体がここに特徴があります。

// if the loc.groups has a value, split it by comma (otherwise use an empty array) 
const groups = loc.groups ? loc.groups.split(",") : []; 

// variable for the cluster map 
const clusters: ClusterMap = {}; 

// for each string (nlc) in the expanded array of loc.nlc (which is 'z'), and all the items in groups (which are a, b, c, d) 
for (const nlc of [loc.nlc, ...groups]) { 
    // add the item to the cluster map with a key of (for example 'z') 
    // and a value of (for exmaple 'z') 
    clusters[nlc] = nlc; 
} 

ネット結果は次のとおりです。例の

{ 
    z: 'z', 
    a: 'a', 
    b: 'b', 
    c: 'c', 
    d: 'd' 
} 

クールな機能:

const arr1 = [1, 2, 3]; 
const arr2 = [4, 5, 6]; 

// 0,1,2,3,4,5,6 
const combined = [0, ...arr1, ...arr2] 
関連する問題