Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Created August 6, 2013 12:02
Show Gist options
  • Save Ahrengot/6163893 to your computer and use it in GitHub Desktop.
Save Ahrengot/6163893 to your computer and use it in GitHub Desktop.
Require a file with require.js
# Here's the method. Filename should be written without the .js extention, so to load a file called
# Main.js you'd type require ["Main"]
require ["url/to/thing/"], ->
# Thing has now been loaded. Continue on
## If you need a reference to the object you just loaded (If the JS file returns an object etc.) you can catch it like this
require ["path/to/thing"], (Thing) ->
window.thing = new Thing()
#But for things like jQuery plugins, google maps api etc, you don't need to catch anything,
# as they automatically bind themselves to wherever they belong.
###
JavaScript syntax:
require(["path/to/thing"], function(thing) {
window.thing = new Thing();
});
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment