Properly scope variables in javascript (not writing coffeescript!)