15. 開始寫程式
⼀切就緒,我們可以開始寫程式了,寫程式也有幾個要點需要注意:
1. 命名規則
不要再⽤ a, b 來命名你的變數了,給他⼀個有意義的字吧!
> var a, b; // no use
> var apple, banana; // be significant
如果⼀個單字無法解釋意義,⽤單駝峰式來命名:
> var jason_mom, how_many_apples; // not good
> var jasonMom, howManyApples; // be better
函式請多給個動詞,分別意義:
> function doGetContent() { … }
> function countApples() { … }
模組請雙駝峰命名、常數請全⼤
寫:
> class JasonApples { … }
> const JASON_AGE;
15