8000 Update code style · HowProgrammingWorks/Factory@c9aa241 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9aa241

Browse files
committed
Update code style
1 parent 0f3283a commit c9aa241

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

JavaScript/1-object.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ function userFactory1(name, group, email) {
55
}
66

77
const userFactory2 = (name, group, email) => ({
8-
name, group, email,
8+
name,
9+
group,
10+
email,
911
});
1012

1113
const userFactory3 = (name, group, email) => {
1214
name, group, email;
1315
};
1416

15-
const userFactory4 = (name, group, email) => (
16-
name, group, email
17-
);
17+
const userFactory4 = (name, group, email) => (name, group, email);
1818

1919
const user1 = userFactory1('marcus', 'emperors', 'marcus@spqr.it');
2020
console.log(user1);

JavaScript/2-prototype.js

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

33
const logable = (fields) => {
4-
54
function Logable(data) {
65
this.values = data;
76
}
@@ -15,17 +14,14 @@ const logable = (fields) => {
1514
set(value) {
1615
console.log('Writing key:', key, value);
1716
const def = fields[key];
18-
const valid =
19-
typeof value === def.type &&
20-
def.validate(value)
21-
;
17+
const valid = typeof value === def.type && def.validate(value);
2218
if (valid) this.values[key] = value;
2319
else console.log('Validation failed:', key, value);
2420
},
2521
});
2622
}
2723

28-
Logable.prototype.toString = function() {
24+
Logable.prototype.toString = function () {
2925
let result = this.constructor.name + ': ';
3026
for (const key in fields) {
3127
result += this.values[key] + ' ';
@@ -34,7 +30,6 @@ const logable = (fields) => {
3430
};
3531

3632
return Logable;
37-
3833
};
3934

4035
// Usage

JavaScript/3-class.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
'use strict';
22

3-
const logable = (fields) => class Logable {
4-
constructor(data) {
5-
this.values = data;
6-
for (const key in fields) {
7-
Object.defineProperty(Logable.prototype, key, {
8-
get() {
9-
console.log('Reading key:', key);
10-
return this.values[key];
11-
},
12-
set(value) {
13-
console.log('Writing key:', key, value);
14-
const def = fields[key];
15-
const valid =
16-
typeof value === def.type &&
17-
def.validate(value)
18-
;
19-
if (valid) this.values[key] = value;
20-
else console.log('Validation failed:', key, value);
21-
},
22-
});
3+
const logable = (fields) =>
4+
class Logable {
5+
constructor(data) {
6+
this.values = data;
7+
for (const key in fields) {
8+
Object.defineProperty(Logable.prototype, key, {
9+
get() {
10+
console.log('Reading key:', key);
11+
return this.values[key];
12+
},
13+
set(value) {
14+
console.log('Writing key:', key, value);
15+
const def = fields[key];
16+
const valid = typeof value === def.type && def.validate(value);
17+
if (valid) this.values[key] = value;
18+
else console.log('Validation failed:', key, value);
19+
},
20+
});
21+
}
2322
}
24-
}
2523

26-
toString() {
27-
let result = this.constructor.name + '\t';
28-
for (const key in fields) {
29-
result += this.values[key] + '\t';
24+
toString() {
25+
let result = this.constructor.name + '\t';
26+
for (const key in fields) {
27+
result += this.values[key] + '\t';
28+
}
29+
return result;
3030
}
31-
return result;
32-
}
33-
};
31+
};
3432

3533
// Usage
3634

JavaScript/6-factorify.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ class Person {
66
}
77
}
88

9-
const factorify = (Category) => (...args) => new Category(...args);
9+
const factorify =
10+
(Category) =>
11+
(...args) =>
12+
new Category(...args);
1013

1114 3E31
// Usage
1215

0 commit comments

Comments
 (0)
0