| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ In this example, the variable `PI` is private to `circle.js`. | |||
| 38 | 38 | The `module.exports` property can be assigned a new value (such as a function | |
| 39 | 39 | or object). | |
| 40 | 40 | ||
| 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: | ||
| 42 | 42 | ||
| 43 | 43 | ```js | |
| 44 | 44 | const Square = require('./square.js'); | |
@@ -50,10 +50,14 @@ The `square` module is defined in `square.js`: | |||
| 50 | 50 | ||
| 51 | 51 | ```js | |
| 52 | 52 | // 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 | + } | ||
| 57 | 61 | }; | |
| 58 | 62 | ``` | |
| 59 | 63 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments