javascript - when variable is set then (wait until is set then execute) -


i want execute function variable has been set (geoloaction['latitude']). i'm not sure if following code right way use deferreds. unfortunately doesn't work hoping for.

$.when( geolocation['latitude'] ).then( function(){             console.log( 'latitude = ' + geolocation['latitude'] );         }); 

what best/correct way wait until variable has been set , execute function?

wrong use of when:

var d1 = $.deferred(); var d2 = $.deferred(); var d3 = $.deferred();  $.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) {     console.log( v1 ); // v1 undefined     console.log( v2 ); // v2 "abc"     console.log( v3 ); // v3 array [ 1, 2, 3, 4, 5 ] });  d1.resolve(); d2.resolve( "abc" ); d3.resolve( 1, 2, 3, 4, 5 ); 

if can't call function on code can check value with:

setinterval(function(){    if(geolocation['latitude'] != undefined){       console.log( 'latitude = ' + geolocation['latitude'] );   } }, 1); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -