(單獨的)函數在調用時,例如setTimeout()中的函數,如果不是作爲對象的方法或者被bind、call 和 apply 改變 this 值,則該函數中的 this 指向是window,嚴格模式中是 undefined。
函數中的 this 是在函數運行時動態指定的;箭頭函數 this 值是詞法作用域,在定義時就規定了的,在調用時也不會被改變。
參數默認值的寫法:
//舊版寫法functionadd(a,b){
a = a ||5;//默認聲明參數變量,無需再聲明
b = b ||2;return a + b;}//es6寫法functionadd(a=5,b=2){return a + b;}//只傳入後一個值時的寫法add(undefined,5);//10