I am facing a problem while fetching the value from HTML5 localstorage. When i am setting value to the key using JSON.stringify the callback is getting removed. I am stuck with this problem. Below is the code snippet.
var topics = {};
var subscribe = function (topic, fn)
{
if (!topics[topic])
{
topics[topic] = [];}
topics[topic].push({ callback: fn,context: this });
window.localStorage.setItem('myArray', JSON.stringify(topics[topic]));
return this;
};
var publish = function (topic) {
var args;args = Array.prototype.slice.call(arguments, 1);
var myArray = JSON.parse(window.localStorage.getItem('myArray'));
for (var i = 0, l = myArray.length; i < l; i++) {var subscription = myArray[i];
subscription.callback.apply(subscription.context, args);
}
return this;
};
Any help will be highly appreciated.
Cheers, Sajesh Nambiar