Skip to content

Instantly share code, notes, and snippets.

@degizmo
Created February 16, 2011 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save degizmo/828841 to your computer and use it in GitHub Desktop.
Save degizmo/828841 to your computer and use it in GitHub Desktop.
coffeescript variable scoping problems
outer = 1
changeNumbers = ->
inner = -1
outer = 10
inner = changeNumbers()
console.log(outer)
#output = 10
#result out, although outside of the inner scope is altered, which is not prefered
outer = 1
changeNumbers = ->
@inner = -1
@outer = 10
inner = changeNumbers()
console.log(outer)
#output = 1
#the @symbol forces the interior "this" to the outer varible changing it's scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment