Created
February 22, 2013 21:53
-
-
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
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
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