Skip to content

Instantly share code, notes, and snippets.

@vlasovskikh
Created July 23, 2011 12:02
Show Gist options
  • Save vlasovskikh/1101352 to your computer and use it in GitHub Desktop.
Save vlasovskikh/1101352 to your computer and use it in GitHub Desktop.
Local vars in CoffeeScript are nonlocal sometimes
f = ->
x = 2
x = 1
> console.debug "x = #{ x }"
x = 1
> console.debug "f() = #{ f() }"
f() = 2
> console.debug "x = #{ x }"
x = 1
x = 1
f = ->
x = 2
> console.debug "x = #{ x }"
x = 1
> console.debug "f() = #{ f() }"
f() = 2
> console.debug "x = #{ x }"
x = 2
@vlasovskikh
Copy link
Author

@autotelicum Yep, I'm aware of the scoping rules in CoffeScript, but they are a little bit weird from a pythonista's perspective. Thanks for the pointer to your book!

@autotelicum
Copy link

Then this might be more relevant:
http://blog.ssokolow.com/archives/2011/05/07/a-python-programmers-first-impression-of-coffeescript/
If you are interested in the pro/contra of scoping: jashkenas/coffeescript#1121

@vlasovskikh
Copy link
Author

@autotelicum Thanks for these very relevant links! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment