Consider this ClojureScript code:
(defn foo []
(let [location 12345] (prn js/location.hash)))
This won't work. js/
isn't a real namespace. This code will throw an exception at runtime.
The reason is that the code expands to this JS snippet:
cljs.user.foo = (function cljs$user$foo(){
var location = (12345);
return cljs.core.prn.call(null,location.hash);
});
As you can see, the location
let binding is shadowing the js/location
var.
The moral of the story is: be careful when using global vars like js/window
and js/location
.
Don't use them in the context of let bindings or function arguments with common names like
window
or location
.