Today in “Things not to do when writing Javascript”
Pop quiz: what’s wrong with this piece of code?
function foo() {
var route = route();
// ...
}
The answer: it won’t do anything. That’s because in Javascript, everything is an object, including functions and variables, and they all share the same name space. By declaring a variable called route
in the current scope, the function route()
from the surrounding scope is hidden.