Q:

Storage.prototype not working in IE8

I have been trying to get this to work in IE8 and while it does not complain about these it completely ignores them.
if( typeof(Storage) != "undefined"){
    Storage.prototype.setObject = function(key, value) {
          this.setItem(key, escape(JSON.stringify(value)));
    }   

    Storage.prototype.getObject = function(key) {       
        return JSON.parse(unescape(this.getItem(key)));
    }
}

When I try:
localStorage.setObject("key", <Some object>);

I get an "Object does not support this method" error raised and the function is not even called. Of course this code works fine in Chrome and Firefox and probably even on my 1980's Casio watch.
Any help would be great.
Incidental and completely unrelated the IE8 when I get my object back I have to JSON.parse it twice to get the object... 
Thanks
Paul

A:

You'd be better off using a separate function instead of messing with the prototype of a built-in object.
function storeObject(key,obj) {
    localStorage[key] = JSON.stringify(obj);
}
function retrieveObject(key) {
    return JSON.parse(localStorage[key]);
}

This is more reliable than prototype operations, particularly in older browsers.

