4 ms·
The description of how require() works is not quite correct. Node does not always fully initialize the dependency module before returning from require(). It can
by foreigner 6y ago
The description of how require() works is not quite correct. Node does not always fully initialize the dependency module before returning from require(). It can't work that way, because Node allows circular require() dependencies. Try it!
- dimgl 6y ago> Node does not always fully initialize the dependency module before returning from require(). Unsure what this means. The only reason this happens is because an unfinished copy is provided to the dependency that is causing a circular reference.
- dsun179 6y agoThe reason is not correct. Nodejs cache the require lot and so circular dependencies can work without returning half finished loads.
- foreigner 6y agoNodejs does cache the results of require(), but that doesn't help with this problem. Example: https://repl.it/repls/SwiftOlivedrabBrace https://repl.it/repls/SwiftOlivedrabBrace