Skip to content

Commit 70bb265

Browse files
committed
minor fixes
1 parent 842f0e2 commit 70bb265

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

1-js/13-modules/01-modules-intro/article.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ That's exactly because the module is executed only once. Exports are generated,
188188

189189
In other words, a module can provide a generic functionality that needs a setup. E.g. authentication needs credentials. Then it can export a configuration object expecting the outer code to assign to it.
190190

191-
For instance, the `admin.js` module may provide certain functionality (e.g. authentication), but expect the credentials to come into the `config` object from outside.
191+
Here's a classical pattern:
192+
1. A module exports some means of configuration, e.g. a configuration object.
193+
2. On the first import we initialize it, write to its properties. The top-level application script may do that.
194+
3. Further imports use the module.
195+
196+
For instance, the `admin.js` module may provide certain functionality, but expect the credentials to come into the `config` object from outside:
192197

193-
First, we can export the `config` object (here it's initially empty, but that's not always the case):
194198
```js
195199
// 📁 admin.js
196200
export let config = { };
@@ -200,6 +204,8 @@ export function sayHi() {
200204
}
201205
```
202206

207+
Here, `admin.js` exports the `config` object (initially empty, but that's not always the case).
208+
203209
Then in `init.js`, the first script of our app, we set `config.user`:
204210

205211
```js
@@ -208,7 +214,9 @@ import {config} from './admin.js';
208214
config.user = "Pete";
209215
```
210216

211-
...Now the module is configured. It's `config` property has the right user, and it can say hi to them (or provide authentication or whatever):
217+
...Now the module is configured.
218+
219+
Further importers can call it, and it correctly shows the current user:
212220

213221
```js
214222
// 📁 another.js
@@ -217,10 +225,6 @@ import {sayHi} from './admin.js';
217225
sayHi(); // Ready to serve, *!*Pete*/!*!
218226
```
219227

220-
Here's a classical pattern:
221-
1. A module exports some means of configuration.
222-
2. On the first import we initialize it.
223-
3. Further imports use the module.
224228

225229
### import.meta
226230

0 commit comments

Comments
 (0)