nbubna/store — pull request #18 by annez (2014-07-21 13:29:09+00:00)
Title: Closure compiler removes try/catch block on localStorage/sessionStorage check

Please see:

https://code.google.com/p/closure-compiler/issues/detail?id=64
https://code.google.com/p/closure-compiler/issues/detail?id=506
https://code.google.com/p/closure-compiler/issues/detail?id=451

Basically when compiling with the Closure Compiler, the output code for this line

``` javascript
_.Store("local", (function(){try{ return localStorage; }catch(e){}})());
```

Gets output to:
``` javascript
_.Store("local",function(){return localStorage}());
```
Which will bomb in IE7 and throw a `localStorage is undefined` error.

Thus I've wrapped it in an if statement checking for "localStorage" in window, which will result in the exact same desired effect but with the compiler correctly evaluating the code and keeping the try/catch block.

The other option for this is to use the localStorage variable further down the code so that the Compiler keeps the try catch, but I felt this was a neater way of doing it.

Thoughts?