Skip to content

Commit

Permalink
doc: modernize and fix code examples in modules.md
Browse files Browse the repository at this point in the history
* Replace `var` by `const`.
* Fix semicolons.
* Add missing code marks.
* Unify quotes.
* Comment out ellipsis.
* Use object destructuring.
* Replace snake_case by camelCase.

Backport-PR-URL: #12500
PR-URL: #12224
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Alexey Orlenko <[email protected]>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Apr 24, 2017
1 parent 62e047e commit d15188f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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;

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 @@ -56,10 +56,10 @@ module.exports = (width) => {
return {
area: () => width * width
};
}
};
```

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,16 +565,16 @@ 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() {};
exports = some_func;
function someFunc() {}
exports = someFunc;
// At this point, exports is no longer a shortcut to module.exports, and
// this module will still export an empty default object.
module.exports = some_func;
// At this point, the module will now export some_func, instead of the
module.exports = someFunc;
// At this point, the module will now export someFunc, instead of the
// default object.
})(module, module.exports);
return module.exports;
Expand Down

0 comments on commit d15188f

Please sign in to comment.