You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
poseidonCore edited this page May 7, 2016
·
6 revisions
######RATIONALE
Importantly, modules are initialised when first required in an executed module, and NOT when they are fetched. This behaviour saves memory, but is also more consistent with Node.js. Also, modules are initialised only once (unlike other browser-side requirers). Any reference to a module that resolves to an address will be the same module throughout the entire structure that was spawned from the same loader (original HTML file).
######MECHANISM
When a module is defined, it is stored as an unexectured function with the parameters
require
exports
module
__filename
__dirname
The function is formed in the Global scope and is bound to exports (ie exports is its this). This is consistent with Node.js usage.
The require parameter closes over a function that tells NodalRequire to initialise the module and return a reference to the module.exports. If the module is already initialised, then only the reference to module.exports is returned.