HTML and CSS Reference
In-Depth Information
New type added
This call will create a new object store called testing , and then invoke the success callback
which will log success to the console. After invoking this, the testing item will be available
in localStorage. This can be verified using a shortcut to getItem():
> localStorage.testing
localStorage is just a regular object, therefore its items can be accessed as reg-
ular properties using the dot notation (assuming they adhere to the restictions on
JavaScript variable names).
An important feature of both the init and initObjectStore methods is that they can be in-
voked multiple times and will always return the same output for the same inputs. This is
an important feature, since a client may not know if these have been called by other code.
Rather than requiring the client to find out whether the initialization has occurred, and call
init if it hasn't, the client can simply call init and have it take care of the logic of working
out what needs to be done.
The tasksController will be responsible for calling init and initObjectStore . Before
providing the implementation to call the initialization methods, it is worth thinking about
the error callback. Every time a storage engine method is invoked, an error callback must
be provided.
We will therefore create a generic function that can be used for the errorCallback, and store
this as a private variable in tasksController . All this will do is log the fact that an error
has occurred, but if we want to change the behaviour, we would be able to do so in a single
place, rather than changing all the error callbacks.
The function can be added as a private function within tasksController :
tasksController = function() {
function errorLogger(errorCode, errorMessage) {
console.log(errorCode +':'+ errorMessage);
Search WWH ::

Custom Search