Created
August 6, 2013 12:02
-
-
Save Ahrengot/6163893 to your computer and use it in GitHub Desktop.
Require a file with 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
# 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