Skip to content

Instantly share code, notes, and snippets.

@knjname
Created August 10, 2012 16:54
Show Gist options
  • Save knjname/3315588 to your computer and use it in GitHub Desktop.
Save knjname/3315588 to your computer and use it in GitHub Desktop.
@withGlobals = (prop, fn) =>
swap = => [@[k], prop[k]] = [prop[k], @[k]] for k of prop
try
do swap
do fn
finally
do swap
@withGlobals {alert : (v) -> console.log(v) }, =>
@alert('funge')
try
@alert('honge') # may cause an error
catch e
console.log 'error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment