// // closure 1 function func() { var count = 0; function cal(){ count += 2; console.log(count); return count; } return cal; }; // clo等於func這個函數 // var clo = func;// Uncaught TypeError: func is not a function,func最後不能() // clo等於func這個函數的返回值 var clo = func();// Uncaught TypeError: func is not a function,var func = function(){} clo();// 2 clo();// 4 // closure 2 var segment = (function(){ let count = 0;// must init =0, support let return function(){ count++; console.log(count); } })();// 不能用!,要(),由於!有返回值,不是true就是false,不可能爲function segment();// 1 segment();// 2