带有settimeout函数的javascript闭包

时间:2012-02-01 13:06:52

标签: javascript closures settimeout

如何在具有settimeout函数的闭包中表达这一点,以在运行API之前或之后创建2秒暂停。请注意,geocoder.geocode是异步的。

function srPerformGeocode(addressToArray, nextRecord){                             

        var address = addressToArray.join(",");
        console.log(address);                    

        if (geocoder){                                                   
            glDelay = true;
            geocoder.geocode({ 'address': address.trim() }, function
            (results, status) {
                // count number of geocodings attempted
                glGeocodeCount ++;                                                       
                if (status == google.maps.GeocoderStatus.OK){            
                }
                else{
                }
            });
        }
}   

1 个答案:

答案 0 :(得分:2)

setTimeout (function ()
{
    geocoder.geocode( ... );

}, 2000);