Created
February 3, 2011 00:53
-
-
Save jrburke/808837 to your computer and use it in GitHub Desktop.
Sample layout for a one two three
This file contains hidden or 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
/* | |
Directory layout | |
app.html | |
scripts | |
- require.js | |
- one.js | |
- two.js | |
- three.js | |
*/ | |
//In scripts/one.js | |
var oneName = 'one'; | |
//In scripts/two.js | |
var twoName = 'two'; | |
//In scripts/three.js | |
define(['one', 'two'], function () { | |
return { | |
name: 'three', | |
//These two reference the globals created by one.js and two.js | |
twoName: twoName, | |
oneName: oneName | |
}; | |
}); | |
//in a script tag in app.html, it loads scripts/require.js then | |
//it does the following in a script block. | |
//Since three defines a module, then the function | |
//passed to require will receive the module value | |
require(['three'], function (three) { | |
console.log("Three's name: " + three.name); | |
console.log("One's name: " + three.oneName); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment