Created
October 26, 2012 14:19
-
-
Save raglan-road/3959086 to your computer and use it in GitHub Desktop.
promises thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initMap = function(){ | |
var self = this; | |
return $.Deferred(function(dfd){ | |
if(self.mapLoaded){ | |
// Map is loaded y'all. | |
dfd.resolve(); | |
} | |
else{ | |
$.ajax( // load your thing) | |
.done(function(){ | |
// Map loaded correctly? Set our mapLoaded flag and resolve our promise | |
self.mapLoaded = true; | |
dfd.resolve(); | |
}); | |
} | |
}).promise(); | |
} | |
// ... and then | |
$.when(this.initMap()) | |
.done(function(){ | |
// Maps are loaded! This will either execute after your Ajax request | |
// if the map isn't loaded or immediately if the map is already loaded. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment