HTML and CSS Reference
In-Depth Information
If the property does exist, we ensure that it is an integer with the parseInt function. For in-
stance, if we are passed a number as a string, then we convert it to a number. This is anoth-
er important consideration, since the toObject implementation currently always produces
strings.
//
This is the first time we have seen the native JavaScript parseInt function. Al-
though this is a useful function, it does have its problems. In order to see these
first hand, try the following call:
> parseInt(010)
It will be left to the reader to discover why this returns 8 rather than 10.
Next we create a transaction in the database and add onerror and onsuccess callbacks to it:
var tx = database.transaction([type], "readwrite");
tx.oncomplete = function(event) {
successCallback(obj);
};
tx.onerror = function(event) {
errorCallback('transaction_error', 'It is not possible to store the object');
};
We can only access an object store in the context of a transaction. A transaction groups to-
gether a set of operations on one or more object stores. The transaction will auto-commit
once all requests against the transaction have completed.
It is not until the transaction completes that we will notify the client of success. If we noti-
fied the client after the requests had been submitted they might encounter a situation where
they cannot query the object store for the objects. This is because all changes to the object
store will remain hidden from all clients until the transaction commits.
//
The transaction is specified as a “readwrite” transaction: you must specify this
if you want to modify objects in an object store. The default transaction type is
“read”. It may seem strange that a transaction is required even to read objects.
 
Search WWH ::




Custom Search