使用while循环创建一些东西

时间:2016-02-07 14:49:43

标签: javascript while-loop

为什么这不起作用?如何改进它以使其有效?

...

showCurrent(passLatLon); // first call, coordinates unresolved

var param={
lat:selectLat,
lon:selectLon,
};

function getResults(param, function(data){
    alert(JSON.stringify(data)); // still unresolved
}

// somewhere around here geolocation service kicks in and passes
// coordinates to `passLatLon` function

// if you try to look at selectLat/selectLon at this point of executin,
// they will contain values from previous probe

1 个答案:

答案 0 :(得分:0)

使用while (1 == 1)会导致阻塞语句,并且不会执行其他代码。尝试替换

while (1 == 1) {
    window.setTimeout(moveCharacter, 400);}

setInterval()

window.setInterval(moveCharacter, 400);