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 329f3de

Browse filesBrowse files
apapirovskigibfahn
authored andcommitted
doc: fix modules.md export example
Arrow functions cannot be called with the new keyword, convert to ES6 classes instead. PR-URL: #17579 Refs: #17364 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e93a6da commit 329f3de
Copy full SHA for 329f3de

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+9
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/modules.md‎

Copy file name to clipboardExpand all lines: doc/api/modules.md
+9-5Lines changed: 9 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In this example, the variable `PI` is private to `circle.js`.
3838
The `module.exports` property can be assigned a new value (such as a function
3939
or object).
4040

41-
Below, `bar.js` makes use of the `square` module, which exports a constructor:
41+
Below, `bar.js` makes use of the `square` module, which exports a Square class:
4242

4343
```js
4444
const Square = require('./square.js');
@@ -50,10 +50,14 @@ The `square` module is defined in `square.js`:
5050

5151
```js
5252
// assigning to exports will not modify module, must use module.exports
53-
module.exports = (width) => {
54-
return {
55-
area: () => width ** 2
56-
};
53+
module.exports = class Square {
54+
constructor(width) {
55+
this.width = width;
56+
}
57+
58+
area() {
59+
return this.width ** 2;
60+
}
5761
};
5862
```
5963

0 commit comments

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