Skip to content

Commit

Permalink
doc: fix modules.md export example
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
apapirovski authored and MylesBorins committed Dec 12, 2017
1 parent 54cd7df commit ccffbd9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ In this example, the variable `PI` is private to `circle.js`.
The `module.exports` property can be assigned a new value (such as a function
or object).

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

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

```js
// assigning to exports will not modify module, must use module.exports
module.exports = (width) => {
return {
area: () => width ** 2
};
module.exports = class Square {
constructor(width) {
this.width = width;
}

area() {
return this.width ** 2;
}
};
```

Expand Down

0 comments on commit ccffbd9

Please sign in to comment.