Skip to content

Instantly share code, notes, and snippets.

@jurriaan
Created January 20, 2011 13:20
Show Gist options
  • Save jurriaan/787857 to your computer and use it in GitHub Desktop.
Save jurriaan/787857 to your computer and use it in GitHub Desktop.
Scope problems
test = {
'a': ->
console.log 1
'b': ->
console.log 2
}
test2 = {}
for title, func of test
console.log title
test2[title] = =>
func()
test2['a']()
test2['b']()
# Output:
# a
# b
# 2
# 2
# Wanted output:
# a
# b
# 1
# 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment