Time for action – creating a localStorage wrapper

To help get around some of the limitations of localStorage we are going to create an object called AppStorage that provides a wrapper over the localStorage object. The AppStorage object will help us avoid key collisions and provide an easy way to store non-string values. Let's define this object in a new file called appStorage.js, so we can reuse it in all of our applications. You can find the code for this section in Chapter 1/example1.3.

function AppStorage(appName)
    var prefix = (appName ? appName + "." : "");

The constructor takes in the application name as a parameter. The next line sets a private variable named prefix that will be used to prefix all of our keys with the application name to ...

Get HTML5 Web Application Development By Example Beginner's guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.