async-define.js
function _define(/* <exports>, name, dependencies, factory */) {
            var
                // extract arguments
                argv = arguments,
                argc = argv.length,

                // extract arguments from function call - (exports?, name?, modules?, factory)
                exports = argv[argc - 4] || {},
                name = argv[argc - 3] || Math.floor(new Date().getTime() * (Math.random())), // if name is undefined or falsy value we add some timestamp like to name.
                dependencies = argv[argc - 2] || [],
                factory = argv[argc - 1],

                // helper variables
                params = [],
                dependencies_satisfied = true,
                dependency_name,
                result,
                config_dependencies_iterator = 0,
                dependencies_iterator = 0,
                config_dependencies_index = -1;

            if (DEVELOPMENT) {
                _set_debug_timer();
            }

            // config dependecies
            if (_define.prototype.config_dependencies && _define.prototype.config_dependencies.constructor === Array) {
                var config_dependencies = _define.prototype.config_dependencies || [];

                var config_dependencies_size = config_dependencies.length;
                for (; config_dependencies_iterator < config_dependencies_size; config_dependencies_iterator++) {
                    if (name === config_dependencies[config_dependencies_iterator]) {
                        config_dependencies_index = config_dependencies_iterator;
                    }
                }
                if (config_dependencies_index !== -1) {
                    config_dependencies.splice(config_dependencies_index, 1)
                } else {
                    dependencies = dependencies.concat(config_dependencies);
                }
            }

            // find params
            for (; dependencies_iterator < dependencies.length; dependencies_iterator++) {
                dependency_name = dependencies[dependencies_iterator];

                // if this dependency exists, push it to param injection
                if (modules.hasOwnProperty(dependency_name)) {
                    params.push(modules[dependency_name]);
                } else if (dependency_name === 'exports') {
                    params.push(exports);
                } else {
                    if (argc !== 4) { // if 4 values, is reexecuting
                        // no module found. save these arguments for future execution.
                        define_queue[dependency_name] = define_queue[dependency_name] || [];
                        define_queue[dependency_name].push([exports, name, dependencies, factory]);
                    }

                    dependencies_satisfied = false;
                }
            }

            // all dependencies are satisfied, so proceed
            if (dependencies_satisfied) {
                if (!modules.hasOwnProperty(name)) {
                    // execute this module
                    result = factory.apply(this, params);

                    if (result) {
                        modules[name] = result;
                    } else {
                        // assuming result is in exports object
                        modules[name] = exports;
                    }
                }

                // execute others waiting for this module
                while (define_queue[name] && (argv = define_queue[name].pop())) {
                    _define.apply(this, argv);
                }
            }
        }
function _define(/* <exports>, name, dependencies, factory */) {
            var
                // extract arguments
                argv = arguments,
                argc = argv.length,

                // extract arguments from function call - (exports?, name?, modules?, factory)
                exports = argv[argc - 4] || {},
                name = argv[argc - 3] || Math.floor(new Date().getTime() * (Math.random())), // if name is undefined or falsy value we add some timestamp like to name.
                dependencies = argv[argc - 2] || [],
                factory = argv[argc - 1],

                // helper variables
                params = [],
                dependencies_satisfied = true,
                dependency_name,
                result,
                config_dependencies_iterator = 0,
                dependencies_iterator = 0,
                config_dependencies_index = -1;

            if (DEVELOPMENT) {
                _set_debug_timer();
            }

            // config dependecies
            if (_define.prototype.config_dependencies && _define.prototype.config_dependencies.constructor === Array) {
                var config_dependencies = _define.prototype.config_dependencies || [];

                var config_dependencies_size = config_dependencies.length;
                for (; config_dependencies_iterator < config_dependencies_size; config_dependencies_iterator++) {
                    if (name === config_dependencies[config_dependencies_iterator]) {
                        config_dependencies_index = config_dependencies_iterator;
                    }
                }
                if (config_dependencies_index !== -1) {
                    config_dependencies.splice(config_dependencies_index, 1)
                } else {
                    dependencies = dependencies.concat(config_dependencies);
                }
            }

            // find params
            for (; dependencies_iterator < dependencies.length; dependencies_iterator++) {
                dependency_name = dependencies[dependencies_iterator];

                // if this dependency exists, push it to param injection
                if (modules.hasOwnProperty(dependency_name)) {
                    params.push(modules[dependency_name]);
                } else if (dependency_name === 'exports') {
                    params.push(exports);
                } else {
                    if (argc !== 4) { // if 4 values, is reexecuting
                        // no module found. save these arguments for future execution.
                        define_queue[dependency_name] = define_queue[dependency_name] || [];
                        define_queue[dependency_name].push([exports, name, dependencies, factory]);
                    }

                    dependencies_satisfied = false;
                }
            }

            // all dependencies are satisfied, so proceed
            if (dependencies_satisfied) {
                if (!modules.hasOwnProperty(name)) {
                    // execute this module
                    result = factory.apply(this, params);

                    if (result) {
                        modules[name] = result;
                    } else {
                        // assuming result is in exports object
                        modules[name] = exports;
                    }
                }

                // execute others waiting for this module
                while (define_queue[name] && (argv = define_queue[name].pop())) {
                    _define.apply(this, argv);
                }
            }
        }
function _define ( /* <exports>, name, dependencies, factory */ ) { var // extract arguments argv = arguments , argc = argv . length , // extract arguments from function call - (exports?, name?, modules?, factory) exports = argv [ argc - 4 ] || { } , name = argv [ argc - 3 ] || Math . floor ( new Date ( ) . getTime ( ) * ( Math . random ( ) ) ) , // if name is undefined or falsy value we add some timestamp like to name. dependencies = argv [ argc - 2 ] || [ ] , factory = argv [ argc - 1 ] , // helper variables params = [ ] , dependencies_satisfied = true , dependency_name , result , config_dependencies_iterator = 0 , dependencies_iterator = 0 , config_dependencies_index = - 1 ; if ( DEVELOPMENT ) { _set_debug_timer ( ) ; } // config dependecies if ( _define . prototype . config_dependencies && _define . prototype . config_dependencies . constructor === Array ) { var config_dependencies = _define . prototype . config_dependencies || [ ] ; var config_dependencies_size = config_dependencies . length ; for ( ; config_dependencies_iterator < config_dependencies_size ; config_dependencies_iterator ++ ) { if ( name === config_dependencies [ config_dependencies_iterator ] ) { config_dependencies_index = config_dependencies_iterator ; } } if ( config_dependencies_index !== - 1 ) { config_dependencies . splice ( config_dependencies_index , 1 ) } else { dependencies = dependencies . concat ( config_dependencies ) ; } } // find params for ( ; dependencies_iterator < dependencies . length ; dependencies_iterator ++ ) { dependency_name = dependencies [ dependencies_iterator ] ; // if this dependency exists, push it to param injection if ( modules . hasOwnProperty ( dependency_name ) ) { params . push ( modules [ dependency_name ] ) ; } else if ( dependency_name === 'exports' ) { params . push ( exports ) ; } else { if ( argc !== 4 ) { // if 4 values, is reexecuting // no module found. save these arguments for future execution. define_queue [ dependency_name ] = define_queue [ dependency_name ] || [ ] ; define_queue [ dependency_name ] . push ( [ exports , name , dependencies , factory ] ) ; } dependencies_satisfied = false ; } } // all dependencies are satisfied, so proceed if ( dependencies_satisfied ) { if ( ! modules . hasOwnProperty ( name ) ) { // execute this module result = factory . apply ( this , params ) ; if ( result ) { modules [ name ] = result ; } else { // assuming result is in exports object modules [ name ] = exports ; } } // execute others waiting for this module while ( define_queue [ name ] && ( argv = define_queue [ name ] . pop ( ) ) ) { _define . apply ( this , argv ) ; } } }
the 'define' function
the define function