Skip to content

Commit 3a4d9cb

Browse files
committed
Change functions to lambdas
1 parent 6d0220d commit 3a4d9cb

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

JavaScript/3-callback.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
'use strict';
22

3-
function cloneInterface(anInterface) {
4-
const clone = {};
5-
let key, fn;
6-
for (key in anInterface) {
7-
fn = anInterface[key];
8-
clone[key] = wrapFunction(fn);
9-
}
10-
return clone;
11-
}
12-
13-
function wrapFunction(fn) {
3+
const wrapFunction = fn => {
144
console.log('Wrap function: ' + fn.name);
155
return (...args) => {
166
console.log('Called wrapper for: ' + fn.name);
@@ -33,7 +23,17 @@ function wrapFunction(fn) {
3323
console.dir({ result });
3424
return result;
3525
};
36-
}
26+
};
27+
28+
const cloneInterface = anInterface => {
29+
const clone = {};
30+
let key, fn;
31+
for (key in anInterface) {
32+
fn = anInterface[key];
33+
clone[key] = wrapFunction(fn);
34+
}
35+
return clone;
36+
};
3737

3838
// Usage
3939

JavaScript/4-wrap-api.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
'use strict';
22

3-
function cloneInterface(anInterface) {
4-
const clone = {};
5-
let key, fn;
6-
for (key in anInterface) {
7-
fn = anInterface[key];
8-
clone[key] = wrapFunction(fn);
9-
}
10-
return clone;
11-
}
12-
13-
function wrapFunction(fn) {
3+
const wrapFunction = fn => {
144
console.log('Wrap function: ' + fn.name);
155
return (...args) => {
166
console.log('Called wrapper for: ' + fn.name);
@@ -20,7 +10,17 @@ function wrapFunction(fn) {
2010
console.dir({ result });
2111
return result;
2212
};
23-
}
13+
};
14+
15+
const cloneInterface = anInterface => {
16+
const clone = {};
17+
let key, fn;
18+
for (key in anInterface) {
19+
fn = anInterface[key];
20+
clone[key] = wrapFunction(fn);
21+
}
22+
return clone;
23+
};
2424

2525
// Usage
2626

JavaScript/5-timeout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Wrapper will prevent call after timeout
44

5-
function timeout(msec, fn) {
5+
const timeout = (msec, fn) => {
66
let timer = setTimeout(() => {
77
if (timer) console.log('Function timedout');
88
timer = null;
@@ -14,7 +14,7 @@ function timeout(msec, fn) {
1414
return fn(...args);
1515
}
1616
};
17-
}
17+
};
1818

1919
// Usage
2020

JavaScript/6-timeout-async.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Wrapper will prevent call after timeout
44

5-
function timeout(msec, fn) {
5+
const timeout = (msec, fn) => {
66
let timer = setTimeout(() => {
77
if (timer) console.log('Function timedout');
88
timer = null;
@@ -14,7 +14,7 @@ function timeout(msec, fn) {
1414
return fn(...args);
1515
}
1616
};
17-
}
17+
};
1818

1919
// Usage
2020

JavaScript/b-optimzed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const wrap = (func) => {
1515
return;
1616
}
1717
const res = fn(...args);
18-
counter++
18+
counter++;
1919
return res;
2020
};
2121

0 commit comments

Comments
 (0)