多個JS檔, module, timer
一個Project中使用多個JavaScript檔案
<script src="A.js"></script>
<script src="B.js"></script>timeout
timer的用法跟陷阱
Last updated
<script src="A.js"></script>
<script src="B.js"></script>Last updated
setTimeout(function(){ console.log("timeout"); }, 3000);// closure problem
for(var i=0; i<10;i++){
setInterval(function(){
console.log(i); // 10, 10, ...., 10 !!!
}, 5000);
}
How to fix it ??
1. use ES6的blocked scope keywoard, let
2. use another function to forcely pass by value (i)