Skip to content

Instantly share code, notes, and snippets.

@airhorns
Created January 5, 2011 22:48
Show Gist options
  • Select an option

  • Save airhorns/767173 to your computer and use it in GitHub Desktop.

Select an option

Save airhorns/767173 to your computer and use it in GitHub Desktop.
hash = {foo: 1, bar: 2, baz: 3}
handlers = []
for key, val of hash
callback = ->
console.log "Callback has been called for key #{key}"
handlers[val] = callback
handlers[1].call() # outputs 'baz' instead of the expected 'foo', because baz was the last key assigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment