Closed michaelarthurcaulfield closed 9 years ago
will also freeze with other localStorage keywords
Good catch. But @paul90, how did you even think to suspect this? I've not seen this behavior mentioned in any localStorage documentation.
Many thanks to @michaelarthurcaulfield and his students.
Not seen it mentioned anywhere either, but there are some hints. At least one question points to DOM Storage guide
Note: Although the values can be set and read using the standard JavaScript property access method, using the getItem and setItem methods is recommended.
I also noticed that trying to follow the link to 'clear' also empties localstorage, which is a bit of a give away. Although the error in the Firefox console points to JSON.parse.
I'm reminded of little Bobby Tables. http://xkcd.com/327/
Of course localStorage["clear"]
is the same as localStorage.clear
which clears localStorage, which is a wee bit of a problem.
Other than the recommendation quoted above, most of the JavaScript texts seem to freely mix the use of setItem/getItem, square brackets, and the dot notation with not a word of warning of the trap that is awaiting.
To duplicate, create a page named "Clear". It will freeze in this position:
Not hard to work around, but mentioning in case strings are being evaluated in ways they shouldn't be.
DIscovered by student in my class writing page on the app Clear.