mercredi 1 juillet 2015

javascript/sqlite noob -declaration of variables

I'm trying to learn sqlite ,after some time of learning JS. I've recently found a short tutorial about how to create a to do list with sqlite and JS . here is some of the code:

var html5rocks = {};
html5rocks.webdb = {};
html5rocks.webdb.db = null;

html5rocks.webdb.open = function() {
  var dbSize = 5 * 1024 * 1024; // 5MB
  html5rocks.webdb.db = openDatabase("Todo", "1.0", "Todo manager", dbSize);
}

html5rocks.webdb.createTable = function() {
  var db = html5rocks.webdb.db;
  db.transaction(function(tx) {
    tx.executeSql("CREATE TABLE IF NOT EXISTS todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME)", []);
  });
}

What I don't understand is why the declaration of html5rocks.webdb = {}; and html5rocks.webdb.db = null;' was written like that. How can you assign webdb and webdb.db in that way before you declare them as variables inside 'html5rocks{}?

I've never seen this way to declare variables. Can someone please explain ?

Aucun commentaire:

Enregistrer un commentaire