Created
March 1, 2012 14:37
-
-
Save shawn42/1950190 to your computer and use it in GitHub Desktop.
"using" in coffeescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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