Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created July 16, 2011 11:04
Show Gist options
  • Select an option

  • Save liammclennan/1086262 to your computer and use it in GitHub Desktop.

Select an option

Save liammclennan/1086262 to your computer and use it in GitHub Desktop.
Dependency Injection with Require.js
a.coffee
define(['dep'], (dep) ->
(d) ->
d = d || dep
{ }
)
########################
# Can be required:
########################
b.coffee
define(['a'], (a)->
a = a()
)
########################
# Or in a test:
########################
test.coffee
define(['a'], (a) ->
my_dependency = {}
a = a(my_dependency)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment