Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The scoping issue is real, but it's very easy to mitigate. I think the real issue is to make sure you just don't ever use (file) global variables. You should enforce scope with the "do" operator:

  changeValue = do ->
    value = 42
    lastValue = null
    (newValue) ->
      lastValue = value
      value = newValue
That hides the new variables in a closure and they no longer leak to the the enclosing scope. This is cleaner code overall since you no longer have some variables at the top level where you can't be sure of how many functions are using them without searching.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: