jsprint fiddle
by brigand
HTML
<script src="http://brigand.github.io/jsprint/build/output/jsprint.min.js"></script>
JavaScript
// doLater is a function which takes a callback
// it'll call the callback when it's ready
function doLater(callback){
setTimeout(function(){
callback("We waited 2 seconds");
}, 2000);
};
// This will execute imediatley
jsprint("This is the first message");
// We use doLater to run this code at a later time
doLater(function(message){
// this code will run when doLater calls the callback
jsprint(message);
});
// With async callbacks, any code after it will continue running
// so put any code dependant on the callback, inside the callback
jsprint("This will very likely run before our callback");