The following script outputs 1 2 3 4 5 6 7.. I would assume it would output 0 1 2 3 4 5 ...
In fact, in my actual code I believe the print(lostCnt) always is connected to the latest (acting like a global) last count update. Why is this? And what can I do to have it keep the actual cnt with the constraint that I can't modify any of the code in obj1.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function obj1(parameter, callback){
setTimeout(callback, parameter);
}
function caller(){
function miscFunction(cnt){
document.getElementById("main").appendChild(document.createTextNode(cnt));
}
var lostCnt = 0;
setInterval(
function(){
new obj1(5,
function(){
miscFunction(lostCnt);
});
lostCnt++;
},5000
);
}
</script>
</head>
<body onload="caller();">
<div id="main">
</div>
</body>
</html>
Thanks, and this is my first post