Created
April 28, 2014 08:01
-
-
Save sorrycc/11364897 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Require the module at `name`. | |
* | |
* @param {String} name | |
* @return {Object} exports | |
* @api public | |
*/ | |
function require(name) { | |
var module = require.modules[name]; | |
if (!module) throw new Error('failed to require "' + name + '"'); | |
if (!('exports' in module) && typeof module.definition === 'function') { | |
module.client = module.component = true; | |
module.definition.call(this, module.exports = {}, module); | |
delete module.definition; | |
} | |
return module.exports; | |
} | |
/** | |
* Registered modules. | |
*/ | |
require.modules = {}; | |
/** | |
* Register module at `name` with callback `definition`. | |
* | |
* @param {String} name | |
* @param {Function} definition | |
* @api private | |
*/ | |
require.register = function (name, definition) { | |
require.modules[name] = { | |
definition: definition | |
}; | |
}; | |
/** | |
* Define a module's exports immediately with `exports`. | |
* | |
* @param {String} name | |
* @param {Generic} exports | |
* @api private | |
*/ | |
require.define = function (name, exports) { | |
require.modules[name] = { | |
exports: exports | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment