Skip to content

Instantly share code, notes, and snippets.

@jrburke
Created February 3, 2011 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrburke/808837 to your computer and use it in GitHub Desktop.
Save jrburke/808837 to your computer and use it in GitHub Desktop.
Sample layout for a one two three
/*
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