我們程式都寫好以後,就要開始做 unit test ,雖然說不做 unit test 也不會怎樣,畢竟出來混總是要還的,所以還是做一下測試比較好。
本篇的 GitHub: https://github.com/chnbohwr/redux_with_react
在 ES5 的環境下 var 變數預設會設定在全域範圍,意思就是我不管在哪個括號內定義var函數都會被提升到最高層級,所以當程式有問題的時候就會比較難偵錯。我們看到以下程式碼。
var i = "test";
for(var i=1; i<=10; i++){ console.log(i);}
console.log(i);// 11這邊定義 for 迴圈裡面的變數名稱為 i ,我們期待當結束 for…
Set 集合可以讓我們儲存任何類型的唯一值,從下面的程式來看,我們新增了兩次數字1進去集合裡面,但是一樣的數字會被覆蓋掉,這樣就能確保集合裡面的數值都是唯一值。
var dess = new Set()dess.add(1)//Set {1}dess.add(1)//Set {1}dess.add(2)//Set {1, 2}
什麼是 Destructing (解構)?
傳統來說,我們要取得一個陣列裡面的數值可能會用以下的方法來達成
let a = someArray[0];let b = someArray[1];let c = someArray[2];
如果使用解構的方式可以讓程式碼變得更加簡潔,可讀性更高
let [a, b, c] = someArray;