Last active
December 17, 2015 22:59
-
-
Save jcreamer898/5685754 to your computer and use it in GitHub Desktop.
A way to adjust the module context in require.js
This file contains 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
require(['jquery', 'underscore'], function($, _) { | |
require.s.contexts._.execCb = function(name, callback, args) { | |
return callback.apply({ | |
$: $, | |
_: _ | |
}, args); | |
}; | |
// init app here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jcreamer898 - forgive me for "C-ing" my way into an "A, B" conversation....just happened to see James's reply. Having worked on a couple of large require.js efforts, I can say that having these kinds of dependencies injected as normal deps into the module is a huge help, vs sneaking them in magically - since you can see the dep list of a module quite quickly, and be assured that no other secret deps were lurking that weren't in the list. (Of course you can always have 'secret' deps hanging off the window - but you have to decide how to address that as a team...to allow or not allow modules to touch the window directly...and follow the convention consistently). Going the "inject as normal dep" route more clearly expresses the intent, and doesn't lean in the direction of trampling on open/closed (a dilemma we js devs can fall into a lot b/c of our ability to monkey patch all the things). Just food for thought.