HIJACKING localStorage
in chrome you can hijack basic functions in localStorage and then when they are called later, they call the replaced function.
localStorage.getItem = function(val){ console.log( val ); }
//function (val){ console.log( val ); }
localStorage.getItem( "truck" );
//truck
//undefined
localStorage.getItem2 = function(val){ console.log( val ); }
//function (val){ console.log( val ); }
localStorage.getItem2( "truck" );
//TypeError: Property 'getItem2' of object #<a Storage> is not a function
localStorage keys can be any unicode character.
for( var i = 0; i < 32000; i ++ ){
localStorage[ String.fromCharCode(i) + "_test" ] =
String.fromCharCode(i) + "_test";
}
localStorage does not have a prototype
but, Storage.prototype is the prototype for localStorage, so you can add methods there.
localStorage NAMESPACING
i am wondering how one should namespace content on the same page large data sets seem dangerous.
localStorage private keys
if a key starts with a character that is not property safe, it must be accessed via the array notation localStorage[key] rather than dot notation. using one of these chars in front of all of your keys could prevent you from overwriting key functions.
what are other localStorage hacks that you guys have found?