HTML and CSS Reference
In-Depth Information
alStorage object. This method has been added to the API however, since it is common for
other storage APIs to require initialization before use.
The init method simply checks that the localStorage object is available in the browser. If
it is available, it sets a variable in the storage engine called initialised to true . Due to the
specification of the API, the other methods of the Web storage implementation will not be
able to be invoked unless this method has been called.
The initObjectStore method checks to see whether the localStorage object currently con-
tains an item for the type passed in (e.g. “tasks”). If not, it creates an empty object in loc-
alStorage using the type as the key for the item. It will also keep track of the fact that we
have initialized this object store.
If you reload tasks.html, the following can be executed from the command line to initialize
the storage engine:
> storageEngine.init(function(){
console.log('Storage is initialised');
function(errorCode, errorMessage) {
The init method is passed two functions for the success and error callbacks respectively.
When invoked, these functions simply log the fact that they have been called. This call
should result in the following being printed to the console:
“Storage is initialized”
Likewise, the initObjectStore method can be invoked as follows:
> storageEngine.initObjectStore('testing',
console.log('New type added');
function(errorCode, errorMessage) {
Search WWH ::

Custom Search