What I’m trying to do:
Create my own storage API on top of localStorage so it is easier to use in my own code.
Why?
So it has an API for my purposes and can be extended later.
System:
Chrome Version: Version 22.0.1229.94 m
JSFiddle: http://jsfiddle.net/ttback/kr88W/
Error
The fiddle will trigger an error in Console:
TypeError: Property ‘localStorageSave’ of object # is not a function
This works in IE 8 and Firefox 16.0.1, so I am wondering if I’m missing something or is it a Chrome bug.
Code:
<html>
<head>
<title>JS function not working in Chrome</title>
<script type="text/javascript">
var localStorage = localStorage || {};
localStorage.localStorageSave = function(){
alert("SAVE");
};
localStorage.localStorageSave();
</script>
</head>
<body>
</body>
</html>
When you do
you’re doing the same as
or
You’re in fact not saving a function in localStorage, because localStorage saves only strings.
You can check it with
You get
"string". This isn’t a function and is normal.