JavaScript scoping is a bitch