Edit in JSFiddle

//http://www.jermywells.com

//helper method -->
String.prototype.stripWhitespace = function () {
    return this.replace(/\s+/g, '');
}

//define data stores -->
var stores = {
    foos: 'My Foo Collection',
    tokenStoreName: 'Some Random Store'
};

//define my data store handler object -->
var MyDb = function (availableStores, sessionOrLocal) {
    var self = this;
    //this says what storage we're going to use...
    this.storage = sessionOrLocal || localStorage; //sessionStorage;
    if (typeof self.storage === 'undefined') throw 'web storage is not supported';
    this.clear = function () {
        self.storage.clear();
    };
    this.overWrite = function (store, obj, keyProp) {
        return confirm('object key: ' + obj[keyProp] +
            ' in store: ' + store +
            ' already exists. Do you want to overwrite it?');
    };
    this.saveObject = function (store, obj, keyProp) {
        var keyName = store.stripWhitespace() + '.' + obj[keyProp];
        if (self.storage[keyName] !== undefined) //if true, key is in localStorage.
        if (!self.overWrite(store, obj, keyProp)) //if false, return out of method.
        return;

        try{ self.storage[keyName] = JSON.stringify(obj); } 
        catch(saveError) { throw saveError; }
    };
    this.getObject = function (store, obj, keyProp) {
        var keyName = store.stripWhitespace() + '.' + obj[keyProp];
        return JSON.parse(self.storage[keyName]);
    }
    this.getStore = function (store) {
        var ar = [];
        for (var prop in self.storage) {
            if (prop.split('.')[0] === store.stripWhitespace()) 
                ar.push(JSON.parse(self.storage[prop]));
        }
        return ar;
    }
    this.getAllStoreValues = function () {
        var ar = [];
        for (var prop in self.storage) {
            var store = prop.split('.')[0];
            for (var prop1 in availableStores) {
                if (availableStores[prop1].stripWhitespace() === store) {
                    ar.push({
                        store: availableStores[prop1],
                        obj: JSON.parse(self.storage[prop])
                    });
                    break;
                }
            }
        }
        return ar;
    }
    return this;
}

//instance some data to store-->
var myFoo1 = {
    id: 1,
    name: 'foo1'
};
var myFoo2 = {
    id: 2,
    name: 'foo2'
};
var myFoo3 = {
    id: 3,
    name: 'foo3'
};
var randomObject = {
    key: 1,
    name: 'random thingy'
};

//instance my data store handler object-->
var db = new MyDb(stores, sessionStorage);

//store my data in web storage via my data handler object-->
db.saveObject(stores.foos, myFoo1, 'id');
db.saveObject(stores.foos, myFoo2, 'id');
db.saveObject(stores.foos, myFoo3, 'id');
db.saveObject(stores.tokenStoreName, randomObject, 'key');

//show the results -->
document.getElementById('myFoo1').innerHTML =
    JSON.stringify(db.getObject(stores.foos, myFoo1, 'id'));
document.getElementById('myFoo2').innerHTML =
    JSON.stringify(db.getObject(stores.foos, myFoo2, 'id'));
document.getElementById('myFoo3').innerHTML =
    JSON.stringify(db.getObject(stores.foos, myFoo3, 'id'));
document.getElementById('rand1').innerHTML = 
    JSON.stringify(db.getObject(stores.tokenStoreName, randomObject, 'key'));
document.getElementById('allFoosStore').innerHTML = 
    JSON.stringify(db.getStore(stores.foos));
document.getElementById('allTokenStoreName').innerHTML = 
    JSON.stringify(db.getStore(stores.tokenStoreName));
document.getElementById('allLocalStorage').innerHTML = 
    JSON.stringify(db.getAllStoreValues());



myFoo1: <span id="myFoo1"></span>

<br />
<br />myFoo2: <span id="myFoo2"></span>

<br />
<br />myFoo3: <span id="myFoo3"></span>

<br />
<br />randomObject: <span id="rand1"></span>

<br />
<br />all of the <b>foos</b> store: <span id="allFoosStore"></span>

<br />
<br />all of the <b>tokenStoreName</b> store: <span id="allTokenStoreName"></span>

<br />
<br />all local storage: <span id="allLocalStorage"></span>
span {
    color:gray;
}