Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript/sqlite noob-变量声明_Javascript_Sqlite - Fatal编程技术网

javascript/sqlite noob-变量声明

javascript/sqlite noob-变量声明,javascript,sqlite,Javascript,Sqlite,在学习了一段时间JS之后,我正在尝试学习sqlite。我最近发现了一个关于如何使用sqlite和JS创建待办事项列表的简短教程。下面是一些代码: var html5rocks = {}; html5rocks.webdb = {}; html5rocks.webdb.db = null; html5rocks.webdb.open = function() { var dbSize = 5 * 1024 * 1024; // 5MB html5rocks.webdb.db = open

在学习了一段时间JS之后,我正在尝试学习sqlite。我最近发现了一个关于如何使用sqlite和JS创建待办事项列表的简短教程。下面是一些代码:

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)", []);
  });
}
我不明白的是为什么
html5rocks.webdb={}
html5rocks.webdb.db=null;'就是这样写的。在将它们声明为
'html5rocks{}中的变量之前,如何以这种方式分配
webdb
webdb.db

我从未见过这种声明变量的方法。 有人能解释一下吗

{}是一个对象

[]是一个数组

所以

javascript的好处是:你不需要类,你只需要这样做。如果你创建了一个新的属性,你可以立即使用它

OOP语言通常需要多行代码。在javascript中:existingObject.newProperty='newvalue'

var html5rocks = {};  // object html5rocks is made, and is still empty
html5rocks.webdb = {};  // now html5rocks has a property: Webdb.  Webdb itself is an object.
html5rocks.webdb.db = null; // db, set to null, is added to Webdb (itself a property of html5rocks )