@@ -20,7 +20,7 @@ directory as `foo.js`.
2020Here are the contents of ` circle.js ` :
2121
2222``` js
23- const PI = Math . PI ;
23+ const { PI } = Math ;
2424
2525exports .area = (r ) => PI * r * r;
2626
@@ -44,7 +44,7 @@ Below, `bar.js` makes use of the `square` module, which exports a constructor:
4444
4545``` js
4646const square = require (' ./square.js' );
47- var mySquare = square (2 );
47+ const mySquare = square (2 );
4848console .log (` The area of my square is ${ mySquare .area ()} ` );
4949```
5050
@@ -56,10 +56,10 @@ module.exports = (width) => {
5656 return {
5757 area : () => width * width
5858 };
59- }
59+ };
6060```
6161
62- The module system is implemented in the ` require(" module" ) ` module.
62+ The module system is implemented in the ` require(' module' ) ` module.
6363
6464## Accessing the main module
6565
@@ -142,7 +142,7 @@ To get the exact filename that will be loaded when `require()` is called, use
142142the ` require.resolve() ` function.
143143
144144Putting together all of the above, here is the high-level algorithm
145- in pseudocode of what require.resolve does:
145+ in pseudocode of what ` require.resolve() ` does:
146146
147147``` txt
148148require(X) from module at path Y
@@ -565,16 +565,16 @@ To illustrate the behavior, imagine this hypothetical implementation of
565565` require ()` , which is quite similar to what is actually done by ` require ()` :
566566
567567` ` ` js
568- function require (... ) {
569- var module = { exports: {} };
568+ function require (/* ... */ ) {
569+ const module = { exports: {} };
570570 ((module , exports ) => {
571571 // Your module code here. In this example, define a function.
572- function some_func () {};
573- exports = some_func ;
572+ function someFunc () {}
573+ exports = someFunc ;
574574 // At this point, exports is no longer a shortcut to module.exports, and
575575 // this module will still export an empty default object.
576- module .exports = some_func ;
577- // At this point, the module will now export some_func , instead of the
576+ module .exports = someFunc ;
577+ // At this point, the module will now export someFunc , instead of the
578578 // default object.
579579 })(module , module .exports );
580580 return module .exports ;
0 commit comments