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
define( | |
[ | |
'depA', | |
'depB', | |
'depC' | |
], | |
function (depA, depB, depC) { | |
var myModule = {}; | |
// build your module here | |
myModule.foo = depA.getFoo(); |
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( | |
["modA", "modB"], | |
function (modA, modB) { | |
// do something with modA and modB | |
// when they are fully loaded | |
} | |
); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Using RequireJS</title> | |
<!-- we reference requirejs and tell it that what we want to load is specified in data-main --> | |
<script data-main="scripts/main" src="scripts/require.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
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
Project | |
Project/index.html | |
Project/scripts | |
Project/scripts/require.js | |
Project/scripts/main.js | |
Project/scripts/movie.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 we are loading a "movie" module to use in our callback function | |
require(["movie"], function(Movie) { | |
var a = new Movie(); | |
a.setAttribute('name','terminator'); | |
console.log(a.getAttribute('name')); | |
}); |
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
define("movie", function () { | |
//Constructor | |
var Movie = function () { | |
}; | |
//Private vars and functions | |
var attributes = {}; | |
Movie.prototype = { | |
constructor : Movie | |
,getAttribute : function (key){ |
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
//Constructor | |
var Movie = function () { | |
}; |
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
//Private vars and functions | |
var attributes = {}; |
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
Movie.prototype = { | |
constructor : Movie | |
,getAttribute : function (key){ | |
return attributes[key]; | |
} | |
,setAttribute : function (key,value){ | |
attributes[key] = value; | |
} | |
}; |
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
return Movie; |
OlderNewer