Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 22, 2013 21:53
Show Gist options
  • Save frostney/5016824 to your computer and use it in GitHub Desktop.
Save frostney/5016824 to your computer and use it in GitHub Desktop.
Proof-of-concept for an AMD (Asynchronous module pattern) written in CoffeeScript, inspired by the way how ImpactJS handles modules
do (window = @) ->
cache = {}
window.module = (name) ->
deps = []
requires = (dependencies) ->
deps = if Array.isArray dependencies then dependencies else [dependencies]
{requires, defines}
defines = (functionBody, context = @) ->
callArray = []
for d in deps
callArray.push cache[d] if cache[d]
cache[name] = functionBody.apply(context, callArray)
{requires, defines}
{requires, defines}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment