Skip to content

Instantly share code, notes, and snippets.

@shawn42
Created March 1, 2012 14:37
Show Gist options
  • Save shawn42/1950190 to your computer and use it in GitHub Desktop.
Save shawn42/1950190 to your computer and use it in GitHub Desktop.
"using" in coffeescript
window.using = (namespaces..., block) ->
context = {}
for ns in namespaces
for k, v of ns
if context[k]?
throw "Unable to import namespace: symbol [#{k}] already imported!"
context[k] = v
block(context)
doSomethingToo = =>
using MyApp.Models, MyApp.Util, MyApp.Widgets, (ctx) =>
book = new ctx.Book
author = new ctx.Author
thing = new ctx.Thinger ctx.escape(book.get('name')), ctx.escape(author.get('name'))
doSomething = =>
book = new MyApp.Models.Book
author = new MyApp.Models.Author
thing = new MyApp.Widgets.Thinger MyApp.Util.escape(book.get('name')), MyApp.Util.escape(author.get('name'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment