2015年7月16日 星期四

JavaScript 語言-閉包(Closure)

閉包(Closure):在JavaScript中,函數擁有自己獨立的定義域(Domain),可以宣告自己的變數在函數裡面使用,甚至是忽略外部有相同名稱的變數。
Lexical scoping(詞語範圍):

var x=70;

function closureFunc(){
var x= 100;
return x;
}
console.log(x);//顯示70
console.log(closureFunc())//顯示100



Practical closures

Emulating private methods with closures

Creating closures in loops: A common mistake

Performance considerations

相關資料
MDN

沒有留言:

張貼留言