Question:
Can I override the "default" functions in Javascript?
Background:
After finding out that I had collisions between objects stored in localStorage , I decided that I should apply a prefix to all keys to avoid collisions. Obviously, I could create a wrapper function, but it would be much ahead of the default localStorage.getItem and localStorage.setItem to reduce my prefix.
My example completely destroys Firefox because it calls itself recursively, so it is clearly not close to a solution. Perhaps he clarifies what I want to achieve.
The code:
Storage.prototype.setItem = function(key, value) { this.setItem("prefix"+key, value); }; Storage.prototype.getItem = function(key, value) { return this.getItem("prefix"+key); };
source share