(function () {
var $ = this.jQuery;
this.myExample = function () {};
}());
define(id?, dependencies?, factory);
// Calling define with module ID, dependency array and factory function
define('myModule', ['dep1', 'dep2'], function (dep1, dep2) {
// Define the module value by returning a value.
return function () {};
});
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<!-- 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>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
require(["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"
});
define(function(require, exports, module) {
var a = require('a'),
b = require('b');
// Return the module value
return function () {};
}
);
Example
requirejs.config({
baseUrl: 'js/lib',
// If the module ID starts with "app",
// load it from the js/app directory.
// Paths are relative to the baseUrl,
// and never includes a ".js" extension since
// the paths config could be for a directory.
paths: {
app: '../app'
}
});
requirejs(['jquery', 'canvas', 'app/sub'],
function ($, canvas, sub) {
// Use either Jquery or Canvas libraries
});
requirejs.config({
map: {
'*': {
'foo': 'foo1.2'
},
'some/oldmodule': {
'foo': 'foo1.0'
}
}
})
requirejs.config({
shim: {
'jquery.colorize': {
deps: ['jquery'],
exports: 'jQuery.fn.colorize'
}
}
});
requirejs.config({
config: {
'bar': {
size: 'large'
},
'baz': {
color: 'blue'
}
}
});
define(function (require, exports, module) {
// Will be the value 'large'
var size = module.config().size;
});
require.config( {
baseUrl: "/script",
map: {
'*': {
'jquery': 'jquery-private'
},
'jquery-private': {
'jquery': 'jquery'
}
},
paths: paths,
shim: shim
} );
Get your multiple-choice quiz developed on Backbone and create the Require JS fundamentals, considering: