// fileA.js
B.stuff.doStuff();


// fileB.js
var B = B || {};
B.stuff = B.stuff || {};
B.stuff.doStuff = function() {
    console.log('stuff!');
};
// fileA.js
var b = require('./fileB.js');

b.doStuff();


// fileB.js
exports.doStuff = function() {
    console.log('stuff!');
};
// fileA.js
define('fileA', ['fileB'], function(b) {
    b.doStuff();
});


// fileB.js
define('fileB', function() {
    return {
        doStuff: function() {
            console.log('stuff!');
        }
    }
});
// fileA.js
define(['fileB'], function(b) {
    b.doStuff();
});


// fileB.js
define(function() {
    return {
        doStuff: function() {
            console.log('stuff!');
        }
    }
});
define('moduleName', ['depA', 'depB'], function(depA, depB) {
    return {
        doStuff: function() {
            depA.doStuff();
            depB.doStuff();
        }
    };
});

require(['moduleName', 'jquery'], function(module, $) {
    $(document).ready(function() {
        module.doStuff();
    });
});
// fileA.js
require(['fileB'], function(b) {
    b.doStuff();
});

$.getScript('/fileB.js');


// fileB.js
define('fileB', function() {
    return {
        doStuff: function() {
            console.log('stuff!');
        }
    }
});
// fileA.js
require(['fileB'], function(b) {
    b.doStuff();
});

$.getScript('/fileB.js');


// fileB.js
define('fileB', {
    doStuff: function() {
        console.log('stuff!');
    }
});
// main.js
$('#navbar').on('click', '.register', function(event) {
    event.preventDefault();
    showLoading();
    require(['registration'], function(registration) {
        hideLoading();
        registration.showModal();
    });
});

// registration.js
define(['jquery'], function($) {
    /* lots of code */
    return {
        showModal: function() { /* ... */ };
    }
});
<!--This sets the baseUrl to the "scripts" directory-->
<script data-main="scripts/main.js" src="scripts/require.js"></script>
// /scripts/main.js
require(['fileA', 'fileB'], function(a, b) {
    a.doStuff();
    b.doStuff();
});

// /scripts/fileA.js
define({ /* ... */ });

// /scripts/fileB.js
define({ /* ... */ });

References

Asynchronous Module Definition
github.com/amdjs/amdjs-api/wiki/AMD
CommonJS Modules
wiki.commonjs.org/wiki/Modules/1.1
RequireJS
requirejs.org/docs/api.html