Skip to content

Commit ccffbd9

Browse files
apapirovskiMylesBorins
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 <[email protected]>
1 parent 54cd7df commit ccffbd9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

doc/api/modules.md

+9-5
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)