js關於for循環中的閉包問題

由於js沒有塊級做用域for循環的循環體不是一個做用域你的第一段代碼等效於如下展開web var arr=[]; var i=0; arr.push(function(){console.log(i);}); i++; arr.push(function(){console.log(i);}); i++; arr.push(function(){console.log(i);}); i++; a
相關文章
相關標籤/搜索