Skip to content

Commit 2d5db1d

Browse files
committed
Improve examples code style
1 parent b3e7d15 commit 2d5db1d

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

JavaScript/2-before-after.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict';
22

3-
const wrap = (f, before, after) => (...args) => after(f(...before(...args)));
3+
const wrap =
4+
(f, before, after) =>
5+
(...args) =>
6+
after(f(...before(...args)));
47

58
// Usage
69

JavaScript/3-callback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const interfaceName = {
5454
console.dir({ par1, par2 });
5555
callback(null, { field: 'value' });
5656
return par1;
57-
}
57+
},
5858
};
5959

6060
const cloned = cloneInterface(interfaceName);

JavaScript/4-wrap-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const interfaceName = {
3131
methodAsync(par1, par2, callback) {
3232
console.dir({ method: { par1, par2 } });
3333
callback(null, { field: 'value' });
34-
}
34+
},
3535
};
3636

3737
const cloned = cloneInterface(interfaceName);

JavaScript/6-timeout-async.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ const fn100 = timeout(fn, 100);
2626
const fn200 = timeout(fn, 200);
2727

2828
setTimeout(() => {
29-
fn100('first', (err, data) => {
30-
console.log('Callback', data);
29+
fn100('first', (error, data) => {
30+
console.log({ callback: { error, data } });
3131
});
32-
fn200('second', (err, data) => {
33-
console.log('Callback', data);
32+
fn200('second', (error, data) => {
33+
console.log({ callback: { error, data } });
3434
});
3535
}, 150);

JavaScript/9-cancelable.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
const cancelable1 = (fn) => {
66
const wrapper = (...args) => (fn ? fn(...args) : null);
7-
const cancel = () => fn = null;
7+
const cancel = () => {
8+
fn = null;
9+
};
810
return { call: wrapper, cancel };
911
};
1012

1113
// Mixin
1214

1315
const cancelable2 = (fn) => {
1416
const wrapper = (...args) => (fn ? fn(...args) : null);
15-
wrapper.cancel = () => fn = null;
17+
wrapper.cancel = () => {
18+
fn = null;
19+
};
1620
return wrapper;
1721
};
1822

@@ -22,14 +26,16 @@ const fn = (par) => {
2226
console.log('Function called, par:', par);
2327
};
2428

25-
{ // Return struct
29+
{
30+
// Return struct
2631
const f2 = cancelable1(fn);
2732
f2.call('first');
2833
f2.cancel();
2934
f2.call('second');
3035
}
3136

32-
{ // Mixin
37+
{
38+
// Mixin
3339
const f2 = cancelable2(fn);
3440
f2('first');
3541
f2.cancel();

JavaScript/b-optimzed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const wrap = (f) => {
3838
limit = count || 0;
3939
counter = 0;
4040
return this;
41-
}
41+
},
4242
};
4343

4444
return Object.assign(wrapper, methods);

0 commit comments

Comments
 (0)