/**
 * # demo for define & require
 *
 * define('add', function(require, exports, module) {
 *     module.exports = function add(a, b) {
 *         return a+b;
 *     };
 * });
 *
 * or
 *
 * define('add', function() {
 *     return function add(a, b) {
 *         return a+b;
 *     };
 * });
 *
 * define('sum', function(require) {
 *     var add = require('add');
 *
 *     return function sum(x) {
 *         return x.reduce(function(total, a) {
 *              return add(total, a)
 *         }, 0);
 *     };
 * });
 *
 * var sum = require('sum');
 * console.log(sum([1,2,3,4]));
 */
 
(function(root) {
    'use strict';

    var modules = {};

    function define(name, factory) {
        modules[name] = {
            name: name,
            factory: factory,
            exports: {},
            resolved: false
        };
    }

    function require(name) {
        var module = modules[name];
        if (module === undefined) {
            throw new Error('cannot require module: ' + name);
        }
        if (!module.resolved) {
            var object = module.factory(require, module.exports, module);
            module.exports = object || module.exports;
            module.resolved = true;
        }
        return module.exports;
    }

    require.root = root;

    // build-in module for browser
    if (root.window === root) {
        define('window', function() {
            return root;
        });
        define('document', function(require) {
            var window = require('window');
            return window.document;
        });
    }

    // export root object
    root.snack = {
        define: define,
        require: require,
        modules: modules
    };

})(this);

@@ -1256,34 +1256,8 @@
  %7D%0A%0A
-    require.root = root;%0A%0A
     
@@ -1554,20 +1554,22 @@
  export 
-root
+global
  object%0A
@@ -1661,16 +1661,36 @@
  modules
+,%0A        root: root
 %0A    %7D;%0A

Update define.js