Skip to content

Instantly share code, notes, and snippets.

@jessecravens
Created March 29, 2012 14:31
Show Gist options
  • Save jessecravens/2238006 to your computer and use it in GitHub Desktop.
Save jessecravens/2238006 to your computer and use it in GitHub Desktop.
JavaScript Modules - requireJS
define(
//The name of this module
"one",
//The function to execute when all dependencies have loaded. The arguments
//to this function are the array of dependencies mentioned above.
function(Three) {
function One () {
this.stuff = [];
}
One.prototype = new Three();
console.log("one.js");
//return the One constructor function so it can be used by other modules.
return One;
}
);
require(["order!one", "order!two", "order!three"], function() {
console.log('load complete');
});
define(
//The name of this module
"three",
//The function to execute when all dependencies have loaded. The arguments
//to this function are the array of dependencies mentioned above.
function (Two) {
function Three () {
this.stuff = [];
}
// console.log(Two);
//This will now work
Three.prototype = new Two();
console.log("three.js");
//return the Two constructor function so it can be used by other modules.
return Three;
}
);
define(
//The name of this module
"two",
//The function to execute when all dependencies have loaded. The arguments
//to this function are the array of dependencies mentioned above.
function (One) {
function Two () {
this.stuff = [];
}
//This will now work
// console.log(One);
Two.prototype = new One();
console.log("two.js");
//return the Two constructor function so it can be used by other modules.
return Two;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment