Derek Gathright, Yahoo!
// yuiblog.com/blog/2007/06/12/module-pattern/
myLibrary.fizzbuzz = (function () {
var somePrivateVar = "Fizz";
return {
fizzbuzz: myPrivateVar + " Buzz"
};
})();
// fizzbuzz.js
YUI.add("fizzbuzz", function(Y){
// Private variable
var myPrivateVar = "Fizz";
// Export as public variable
Y.fizzbuzz = myPrivateVar + " buzz";
});
Emerging standards
Eventual goal: ECMAScript Modules. Still just a proposal, and incompatible with ES3. :(

// DOM
YUI().use('node', function (Y) { ... });
// Canvas/SVG/VML graphics
YUI().use('graphics', function (Y) { ... });
// Calendar widget
YUI().use('calendar', function (Y) { ... });
// YQL client
YUI().use('yql', function (Y) { ... });
So we organized into modules, great!
<head>
<script src='/js/coreLibrary.js'> </script>
<script src='/js/moduleA.js'> </script>
<script src='/js/moduleB.js'> </script>
<script src='/js/moduleC.js'> </script>
<script src='/js/moduleD.js'> </script>
...
</head>
To optimize and simplify the process of loading modules.
How?
YUI Modules example (again)
// fizzbuzz.js
YUI.add("fizzbuzz", function(Y){
// Private variable
var myPrivateVar = "Fizz";
// Export as public variable
Y.fizz = myPrivateVar + " buzz"
}
<!DOCTYPE html>
<html>
<script src='http://yuim.in/'></script>
<script>
YUI().use('fizzbuzz', function(Y) {
console.log(Y.fizz) // "Fizz buzz"
});
</script>
</html>
<!DOCTYPE html>
<html>
<script src='http://yuim.in/'></script>
<script>
YUI({
modules:{
fizzbuzz:{ fullpath: 'path/to/fizzbuzz.js' }
}
}).use('fizzbuzz', function(Y) {
console.log(Y.fizz) // "Fizz buzz"
});
</script>
</html>
// Example @ http://jsfiddle.net/derek/sfcsE/
YUI({
modules: {
'jquery': {
fullpath: 'jquery.min.js',
condition: 'before' },
'jCarousel': {
fullpath: 'jquery.jcarousel.min.js',
requires: ['jquery', 'jCarouselCSS'] },
'jCarouselCSS': {
fullpath: 'skin.css',
requires: ['jCarouselCSS'],
type: 'css' }
}
}).use('jCarousel', function(Y) { ... });

Addresses the problem of one-module-per-HTTP-request.
Instead of:
GET moduleA.js
GET moduleB.js
GET moduleC.js
= 3 HTTP requests
You get:
GET moduleA.js&moduleB.js&moduleC.js
= 1 HTTP requestWhat about long URLs?
GET moduleA.js&moduleB.js&moduleC.js
GET moduleD.js&moduleE.js&moduleF.js
= 2 HTTP requests
Questions, comments -> @derek