Skip to content
Closed
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ directory as `foo.js`.
Here are the contents of `circle.js`:

```js
const PI = Math.PI;
const { PI } = Math;

exports.area = (r) => PI * r * r;
exports.area = (r) => PI * r ** 2;

exports.circumference = (r) => 2 * PI * r;
```
Expand All @@ -44,7 +44,7 @@ Below, `bar.js` makes use of the `square` module, which exports a constructor:

```js
const square = require('./square.js');
var mySquare = square(2);
const mySquare = square(2);
console.log(`The area of my square is ${mySquare.area()}`);
```

Expand All @@ -54,12 +54,12 @@ The `square` module is defined in `square.js`:
// assigning to exports will not modify module, must use module.exports
module.exports = (width) => {
return {
area: () => width * width
area: () => width ** 2
};
}
};
```

The module system is implemented in the `require("module")` module.
The module system is implemented in the `require('module')` module.

## Accessing the main module

Expand Down Expand Up @@ -142,7 +142,7 @@ To get the exact filename that will be loaded when `require()` is called, use
the `require.resolve()` function.

Putting together all of the above, here is the high-level algorithm
in pseudocode of what require.resolve does:
in pseudocode of what `require.resolve()` does:

```txt
require(X) from module at path Y
Expand Down Expand Up @@ -565,11 +565,11 @@ To illustrate the behavior, imagine this hypothetical implementation of
`require()`, which is quite similar to what is actually done by `require()`:

```js
function require(...) {
var module = { exports: {} };
function require(/* ... */) {
const module = { exports: {} };
((module, exports) => {
// Your module code here. In this example, define a function.
function some_func() {};
function some_func() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good opportunity to convert this identifier to camelCase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aqrln Sure)

exports = some_func;
// At this point, exports is no longer a shortcut to module.exports, and
// this module will still export an empty default object.
Expand Down