Showing posts from August, 2011

Bitten By Bugs - the Asynchronous Way

Can you tell why the following code produces this output? Source: function getHighScores () { var highScoresDb = openDatabase('highScores', '1.0', 'My High Score list', 25500); var highScores = []; highScoresDb.transaction( function ( tx ) { tx.executeSql("select * from hiscores order by score desc", [], function ( tx, results ) { for ( var i = 0; i < results.rows.length; i++ ) { highScores.push( results.rows.item( i ) ); } console.log( "Num scores accumulated: ", highScores.length - 1 ); }); }); return highScores; } var highScores = getHighScores(); console.log( "Num high scores returned: ", highScores.length - 1 ); Output: Given the title of this post it might not be very hard to spot what's going on - but if you got your mind dialed in on procedural programming,