@@ -20,9 +20,9 @@ directory as `foo.js`.
20
20
Here are the contents of ` circle.js ` :
21
21
22
22
``` js
23
- const PI = Math . PI ;
23
+ const { PI } = Math ;
24
24
25
- exports .area = (r ) => PI * r * r ;
25
+ exports .area = (r ) => PI * r ** 2 ;
26
26
27
27
exports .circumference = (r ) => 2 * PI * r;
28
28
```
@@ -44,7 +44,7 @@ Below, `bar.js` makes use of the `square` module, which exports a constructor:
44
44
45
45
``` js
46
46
const square = require (' ./square.js' );
47
- var mySquare = square (2 );
47
+ const mySquare = square (2 );
48
48
console .log (` The area of my square is ${ mySquare .area ()} ` );
49
49
```
50
50
@@ -54,12 +54,12 @@ The `square` module is defined in `square.js`:
54
54
// assigning to exports will not modify module, must use module.exports
55
55
module .exports = (width ) => {
56
56
return {
57
- area : () => width * width
57
+ area : () => width ** 2
58
58
};
59
- }
59
+ };
60
60
```
61
61
62
- The module system is implemented in the ` require(" module" ) ` module.
62
+ The module system is implemented in the ` require(' module' ) ` module.
63
63
64
64
## Accessing the main module
65
65
@@ -142,7 +142,7 @@ To get the exact filename that will be loaded when `require()` is called, use
142
142
the ` require.resolve() ` function.
143
143
144
144
Putting 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:
146
146
147
147
``` txt
148
148
require(X) from module at path Y
@@ -565,16 +565,16 @@ To illustrate the behavior, imagine this hypothetical implementation of
565
565
` require ()` , which is quite similar to what is actually done by ` require ()` :
566
566
567
567
` ` ` js
568
- function require (... ) {
569
- var module = { exports: {} };
568
+ function require (/* ... */ ) {
569
+ const module = { exports: {} };
570
570
((module , exports ) => {
571
571
// Your module code here. In this example, define a function.
572
- function some_func () {};
573
- exports = some_func ;
572
+ function someFunc () {}
573
+ exports = someFunc ;
574
574
// At this point, exports is no longer a shortcut to module.exports, and
575
575
// 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
578
578
// default object.
579
579
})(module , module .exports );
580
580
return module .exports ;
0 commit comments