Created
March 29, 2012 14:31
-
-
Save jessecravens/2238006 to your computer and use it in GitHub Desktop.
JavaScript Modules - requireJS
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( | |
//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; | |
} | |
); |
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(["order!one", "order!two", "order!three"], function() { | |
console.log('load complete'); | |
}); |
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( | |
//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; | |
} | |
); |
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( | |
//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