setTimeout in loop to check for a change in bounds
问题 This is my code: var b; while(!b){ setTimeout(function(){ alert('sss') b=1; }, 500); } and it will not alert 'sss' What can i do? Updated: I want to get bounds on google maps v3: function get_bounds(){ var bounds_; while(!bounds_){ setTimeout(function(){ bounds_=map.getBounds(); if(bounds_){ var leftBottom=[bounds_.getSouthWest().lat(),bounds_.getSouthWest().lng()] var rightTop=[bounds_.getNorthEast().lat(),bounds_.getNorthEast().lng()] return [leftBottom,rightTop]; } }, 500); } } updated2: