All notes


RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node.

It implements the Asynchronous Module API.

<!-- ---------- main.html -->

<!-- data-main attribute tells require.js to load
     scripts/main.js after require.js loads. -->
<script data-main="scripts/main" src="scripts/require.js"></script>

<!-- ---------- main.js -->

<!-- Inside of main.js, you can use requirejs() to load any other scripts you need to run. This ensures a single entry point, since the data-main script you specify is loaded asynchronously. -->

requirejs(["helper/util"], function(util) {
    //This function is called when scripts/helper/util.js is loaded.
    //If util.js calls define(), then this function is not fired until util's dependencies have loaded, and the util argument will hold the module value for "helper/util".



module_id /*optional*/, 
[dependencies] /*optional*/, 
definition function /*function for instantiating the module or object*/

// Example

  ['foo', 'bar'], 
  // module definition function
  // dependencies (foo and bar) are mapped to function parameters
  function ( foo, bar ) {
    // return a value that defines the module export
    // (i.e the functionality we want to expose for consumption)
    // create your module here
    var myModule = {
        console.log('Yay! Stuff');

    return myModule;