Skip to content

Commit f3289f0

Browse files
committed
Add module mixins example
1 parent ee2ba72 commit f3289f0

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

NodeJS/1-mixin/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
require('./unit1.js');
4+
require('./unit2.js');

NodeJS/1-mixin/unit1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const fs = require('node:fs');
4+
5+
const { readFile } = fs;
6+
7+
fs.readFile = (fileName, callback) => {
8+
fs.readFile.calls++;
9+
readFile(fileName, (error, data) => {
10+
fs.readFile.callbacks++;
11+
callback(error, data);
12+
});
13+
};
14+
15+
fs.readFile.calls = 0;
16+
fs.readFile.callbacks = 0;

NodeJS/1-mixin/unit2.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const fs = require('node:fs');
4+
5+
fs.readFile('./main.js', (error, data) => {
6+
const { calls, callbacks } = fs.readFile;
7+
fs.readFile.callbacks = 0;
8+
if (error) {
9+
console.log({ error, calls, callbacks });
10+
} else {
11+
console.log({ data, calls, callbacks });
12+
}
13+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy