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