Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e8991c

Browse filesBrowse files
vsemozhetbytItalo A. Casas
authored andcommitted
doc: modernize and fix code examples in modules.md
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Use exponentiation operator. * Replace snake_case by camelCase. PR-URL: #12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
1 parent 376f5ef commit 3e8991c
Copy full SHA for 3e8991c

File tree

Expand file treeCollapse file tree

1 file changed

+13
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-13
lines changed
Open diff view settings
Collapse file

‎doc/api/modules.md‎

Copy file name to clipboardExpand all lines: doc/api/modules.md
+13-13Lines changed: 13 additions & 13 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ directory as `foo.js`.
2020
Here are the contents of `circle.js`:
2121

2222
```js
23-
const PI = Math.PI;
23+
const { PI } = Math;
2424

25-
exports.area = (r) => PI * r * r;
25+
exports.area = (r) => PI * r ** 2;
2626

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

4545
```js
4646
const square = require('./square.js');
47-
var mySquare = square(2);
47+
const mySquare = square(2);
4848
console.log(`The area of my square is ${mySquare.area()}`);
4949
```
5050

@@ -54,12 +54,12 @@ The `square` module is defined in `square.js`:
5454
// assigning to exports will not modify module, must use module.exports
5555
module.exports = (width) => {
5656
return {
57-
area: () => width * width
57+
area: () => width ** 2
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
142142
the `require.resolve()` function.
143143

144144
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:
146146

147147
```txt
148148
require(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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.