@@ -113,7 +113,7 @@ saveCityZipCode(city, zipCode);
113
113
** [ ⬆ nach oben] ( #table-of-contents ) **
114
114
115
115
### Vermeide Mental Mapping
116
- Explizites ist besser als Implizites .
116
+ Explizites ist besser als Implizites .
117
117
118
118
** Schlecht:**
119
119
``` javascript
@@ -266,13 +266,13 @@ function emailClients(clients) {
266
266
267
267
** Gut:**
268
268
``` javascript
269
- function emailClients (clients ) {
269
+ function emailActiveClients (clients ) {
270
270
clients
271
- .filter (isClientActive )
271
+ .filter (isActiveClient )
272
272
.forEach (email);
273
273
}
274
274
275
- function isClientActive (client ) {
275
+ function isActiveClient (client ) {
276
276
const clientRecord = database .lookup (client);
277
277
return clientRecord .isActive ();
278
278
}
@@ -289,7 +289,7 @@ function addToDate(date, month) {
289
289
290
290
const date = new Date ();
291
291
292
- // Es ist schwierig zu sagen was hinzugefügt wird
292
+ // Es ist schwierig zu sagen was laut Funktionsnamen hinzugefügt wird
293
293
addToDate (date, 1 );
294
294
```
295
295
@@ -434,18 +434,20 @@ function showEmployeeList(employees) {
434
434
const expectedSalary = employee .calculateExpectedSalary ();
435
435
const experience = employee .getExperience ();
436
436
437
- let portfolio = employee .getGithubLink ();
438
-
439
- if (employee .type === ' manager' ) {
440
- portfolio = employee .getMBAProjects ();
441
- }
442
-
443
437
const data = {
444
438
expectedSalary,
445
- experience,
446
- portfolio
439
+ experience
447
440
};
448
441
442
+ switch (employee .type ) {
443
+ case ' manager' :
444
+ data .portfolio = employee .getMBAProjects ();
445
+ break ;
446
+ case ' developer' :
447
+ data .githubLink = employee .getGithubLink ();
448
+ break ;
449
+ }
450
+
449
451
render (data);
450
452
});
451
453
}
@@ -467,7 +469,7 @@ function createMenu(config) {
467
469
config .title = config .title || ' Foo' ;
468
470
config .body = config .body || ' Bar' ;
469
471
config .buttonText = config .buttonText || ' Baz' ;
470
- config .cancellable = config .cancellable = == undefined ? config .cancellable : true ;
472
+ config .cancellable = config .cancellable ! == undefined ? config .cancellable : true ;
471
473
}
472
474
473
475
createMenu (menuConfig);
@@ -612,7 +614,7 @@ const addItemToCart = (cart, item) => {
612
614
** Gut:**
613
615
``` javascript
614
616
const addItemToCart = (cart , item ) => {
615
- return [... cart, { item, date : Date .now () }];
617
+ return [... cart, { item, date: Date .now () }];
616
618
};
617
619
```
618
620
@@ -697,11 +699,9 @@ const programmerOutput = [
697
699
}
698
700
];
699
701
700
- const INITIAL_VALUE = 0 ;
701
-
702
702
const totalOutput = programmerOutput
703
- .map (( programmer ) => programmer .linesOfCode )
704
- .reduce ((acc , linesOfCode ) => acc + linesOfCode, INITIAL_VALUE );
703
+ .map (output => output .linesOfCode )
704
+ .reduce ((totalLines , lines ) => totalLines + lines );
705
705
```
706
706
** [ ⬆ nach oben] ( #table-of-contents ) **
707
707
@@ -959,7 +959,7 @@ function makeBankAccount() {
959
959
960
960
// Ein "Setter", wird duch das unten zurückgegebene Objekt public gemacht
961
961
function setBalance (amount ) {
962
- // ... validieren, bevor der Kontostand aktualisiert wird
962
+ // ... validieren bevor der Kontostand aktualisiert wird
963
963
balance = amount;
964
964
}
965
965
@@ -1098,10 +1098,10 @@ einfach `this` zurück und du wirst weitere Methoden verketten können.
1098
1098
** Schlecht:**
1099
1099
``` javascript
1100
1100
class Car {
1101
- constructor () {
1102
- this .make = ' Honda ' ;
1103
- this .model = ' Accord ' ;
1104
- this .color = ' white ' ;
1101
+ constructor (make , model , color ) {
1102
+ this .make = make ;
1103
+ this .model = model ;
1104
+ this .color = color ;
1105
1105
}
1106
1106
1107
1107
setMake (make ) {
@@ -1121,51 +1121,47 @@ class Car {
1121
1121
}
1122
1122
}
1123
1123
1124
- const car = new Car ();
1124
+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' );
1125
1125
car .setColor (' pink' );
1126
- car .setMake (' Ford' );
1127
- car .setModel (' F-150' );
1128
1126
car .save ();
1129
1127
```
1130
1128
1131
1129
** Gut:**
1132
1130
``` javascript
1133
1131
class Car {
1134
- constructor () {
1135
- this .make = ' Honda ' ;
1136
- this .model = ' Accord ' ;
1137
- this .color = ' white ' ;
1132
+ constructor (make , model , color ) {
1133
+ this .make = make ;
1134
+ this .model = model ;
1135
+ this .color = color ;
1138
1136
}
1139
1137
1140
1138
setMake (make ) {
1141
1139
this .make = make;
1142
- // Anmerkung: Gebe this für die Verkettung zurück
1140
+ // Anmerkung: Gebe „ this“ für die Verkettung zurück
1143
1141
return this ;
1144
1142
}
1145
1143
1146
1144
setModel (model ) {
1147
1145
this .model = model;
1148
- // Anmerkung: Gebe this für die Verkettung zurück
1146
+ // Anmerkung: Gebe „ this“ für die Verkettung zurück
1149
1147
return this ;
1150
1148
}
1151
1149
1152
1150
setColor (color ) {
1153
1151
this .color = color;
1154
- // Anmerkung: Gebe this für die Verkettung zurück
1152
+ // Anmerkung: Gebe „ this“ für die Verkettung zurück
1155
1153
return this ;
1156
1154
}
1157
1155
1158
1156
save () {
1159
1157
console .log (this .make , this .model , this .color );
1160
- // Anmerkung: Gebe this für die Verkettung zurück
1158
+ // Anmerkung: Gebe „ this“ für die Verkettung zurück
1161
1159
return this ;
1162
1160
}
1163
1161
}
1164
1162
1165
- const car = new Car ()
1163
+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' )
1166
1164
.setColor (' pink' )
1167
- .setMake (' Ford' )
1168
- .setModel (' F-150' )
1169
1165
.save ();
1170
1166
```
1171
1167
** [ ⬆ nach oben] ( #table-of-contents ) **
@@ -1277,7 +1273,6 @@ class UserAuth {
1277
1273
}
1278
1274
}
1279
1275
1280
-
1281
1276
class UserSettings {
1282
1277
constructor (user ) {
1283
1278
this .user = user;
@@ -1686,7 +1681,7 @@ du die Abdeckungsziele erreichst bevor ein Feature veröffentlicht oder vorhande
1686
1681
1687
1682
** Schlecht:**
1688
1683
``` javascript
1689
- const assert = require ( ' assert' ) ;
1684
+ import assert from ' assert' ;
1690
1685
1691
1686
describe (' MakeMomentJSGreatAgain' , () => {
1692
1687
it (' handles date boundaries' , () => {
@@ -1709,7 +1704,7 @@ describe('MakeMomentJSGreatAgain', () => {
1709
1704
1710
1705
** Gut:**
1711
1706
``` javascript
1712
- const assert = require ( ' assert' ) ;
1707
+ import assert from ' assert' ;
1713
1708
1714
1709
describe (' MakeMomentJSGreatAgain' , () => {
1715
1710
it (' handles 30-day months' , () => {
@@ -1863,29 +1858,29 @@ ignorieren solltest.
1863
1858
** Schlecht:**
1864
1859
``` javascript
1865
1860
getdata ()
1866
- .then ((data ) => {
1867
- functionThatMightThrow (data);
1868
- })
1869
- .catch ((error ) => {
1870
- console .log (error);
1871
- });
1861
+ .then ((data ) => {
1862
+ functionThatMightThrow (data);
1863
+ })
1864
+ .catch ((error ) => {
1865
+ console .log (error);
1866
+ });
1872
1867
```
1873
1868
1874
1869
** Gut:**
1875
1870
``` javascript
1876
1871
getdata ()
1877
- .then ((data ) => {
1878
- functionThatMightThrow (data);
1879
- })
1880
- .catch ((error ) => {
1881
- // Eine Option (Erweckt mehr Aufmerksamkeit als console.log):
1882
- console .error (error);
1883
- // Eine andere Möglichkeit:
1884
- notifyUserOfError (error);
1885
- // Eine andere Möglichkeit:
1886
- reportErrorToService (error);
1887
- // ODER wende alle drei an!
1888
- });
1872
+ .then ((data ) => {
1873
+ functionThatMightThrow (data);
1874
+ })
1875
+ .catch ((error ) => {
1876
+ // Eine Option (Erweckt mehr Aufmerksamkeit als console.log):
1877
+ console .error (error);
1878
+ // Eine andere Möglichkeit:
1879
+ notifyUserOfError (error);
1880
+ // Eine andere Möglichkeit:
1881
+ reportErrorToService (error);
1882
+ // ODER wende alle drei an!
1883
+ });
1889
1884
```
1890
1885
** [ ⬆ nach oben] ( #table-of-contents ) **
1891
1886
@@ -1925,8 +1920,8 @@ class Alpaca {}
1925
1920
const DAYS_IN_WEEK = 7 ;
1926
1921
const DAYS_IN_MONTH = 30 ;
1927
1922
1928
- const songs = [' Back In Black' , ' Stairway to Heaven' , ' Hey Jude' ];
1929
- const artists = [' ACDC' , ' Led Zeppelin' , ' The Beatles' ];
1923
+ const SONGS = [' Back In Black' , ' Stairway to Heaven' , ' Hey Jude' ];
1924
+ const ARTISTS = [' ACDC' , ' Led Zeppelin' , ' The Beatles' ];
1930
1925
1931
1926
function eraseDatabase () {}
1932
1927
function restoreDatabase () {}
@@ -1979,7 +1974,7 @@ class PerformanceReview {
1979
1974
}
1980
1975
}
1981
1976
1982
- const review = new PerformanceReview (user );
1977
+ const review = new PerformanceReview (employee );
1983
1978
review .perfReview ();
1984
1979
```
1985
1980
@@ -2060,7 +2055,7 @@ function hashIt(data) {
2060
2055
const char = data .charCodeAt (i);
2061
2056
hash = ((hash << 5 ) - hash) + char;
2062
2057
2063
- // Convert to 32-bit integer
2058
+ // Zu einem 32-bit Integer konvertieren
2064
2059
hash &= hash;
2065
2060
}
2066
2061
}
@@ -2159,9 +2154,12 @@ Dieser Leitfaden ist in den folgenden Sprachen verfügbar:
2159
2154
- [ alivebao/clean-code-js] ( https://github.com/alivebao/clean-code-js )
2160
2155
- [ beginor/clean-code-javascript] ( https://github.com/beginor/clean-code-javascript )
2161
2156
- ![ kr] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png ) ** Koreanisch** : [ qkraudghgh/clean-code-javascript-ko] ( https://github.com/qkraudghgh/clean-code-javascript-ko )
2157
+ - ![ pl] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png ) ** Polnisch** : [ greg-dev/clean-code-javascript-pl] ( https://github.com/greg-dev/clean-code-javascript-pl )
2162
2158
- ![ ru] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png ) ** Russisch** :
2163
2159
- [ BoryaMogila/clean-code-javascript-ru/] ( https://github.com/BoryaMogila/clean-code-javascript-ru/ )
2164
2160
- [ maksugr/clean-code-javascript] ( https://github.com/maksugr/clean-code-javascript )
2165
2161
- ![ vi] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png ) ** Vietnamesisch** : [ hienvd/clean-code-javascript/] ( https://github.com/hienvd/clean-code-javascript/ )
2162
+ - ![ ja] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png ) ** Japanisch** : [ mitsuruog/clean-code-javascript/] ( https://github.com/mitsuruog/clean-code-javascript/ )
2163
+ - ![ id] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png ) ** Indonesisch** : [ andirkh/clean-code-javascript/] ( https://github.com/andirkh/clean-code-javascript/ )
2166
2164
2167
2165
** [ ⬆ nach oben] ( #table-of-contents ) **
0 commit comments