Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 22, 2013 22:23
Show Gist options
  • Save frostney/5017020 to your computer and use it in GitHub Desktop.
Save frostney/5017020 to your computer and use it in GitHub Desktop.
Different approach for an AMD which doesn't have method chaining and looks more ideomatic in a CoffeeScript environment
do ->
cache = {}
window.module = (name, defines) ->
return undefined unless name and defines
if typeof defines is 'function' then define = defines else {define, require, context} = defines
require = [] unless require?
context = @ unless context?
if typeof require is 'string' then require = [require]
cacheDeps = []
(cacheDeps.push cache[i] if cache[i]) for i in require
cache[name] = define.apply context, cacheDeps
module 'teststring', -> 'test'
module 'testfun', -> (param) -> console.log param
module 'test'
require: ['testfun', 'teststring']
define: (testfun, teststring) -> testfun teststring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment