From d85a63546cbd70b98cb3ebe7689581662ecbe082 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sat, 9 Dec 2017 13:27:31 -0500 Subject: [PATCH] doc: fix modules.md export example Arrow functions cannot be called with the new keyword, convert to ES6 classes instead. PR-URL: https://github.com/nodejs/node/pull/17579 Refs: https://github.com/nodejs/node/pull/17364 Reviewed-By: Rich Trott --- doc/api/modules.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 7b1be55c93f6e8..50fda3591f102b 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -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'); @@ -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; + } }; ```