|
189 | 189 | // bad |
190 | 190 | const obj = { |
191 | 191 | id: 5, |
192 | | - name: 'San Francisco' |
| 192 | + name: 'San Francisco', |
193 | 193 | }; |
194 | 194 | obj[getKey('enabled')] = true; |
195 | 195 |
|
196 | 196 | // good |
197 | 197 | const obj = { |
198 | 198 | id: 5, |
199 | 199 | name: 'San Francisco', |
200 | | - [getKey('enabled')]: true |
| 200 | + [getKey('enabled')]: true, |
201 | 201 | }; |
202 | 202 | ``` |
203 | 203 |
|
|
211 | 211 |
|
212 | 212 | addValue: function (value) { |
213 | 213 | return atom.value + value; |
214 | | - } |
| 214 | + }, |
215 | 215 | }; |
216 | 216 |
|
217 | 217 | // good |
|
220 | 220 |
|
221 | 221 | addValue(value) { |
222 | 222 | return atom.value + value; |
223 | | - } |
| 223 | + }, |
224 | 224 | }; |
225 | 225 | ``` |
226 | 226 |
|
|
258 | 258 | lukeSkywalker, |
259 | 259 | episodeThree: 3, |
260 | 260 | mayTheFourth: 4, |
261 | | - anakinSkywalker |
| 261 | + anakinSkywalker, |
262 | 262 | }; |
263 | 263 |
|
264 | 264 | // good |
|
268 | 268 | episodeOne: 1, |
269 | 269 | twoJedisWalkIntoACantina: 2, |
270 | 270 | episodeThree: 3, |
271 | | - mayTheFourth: 4 |
| 271 | + mayTheFourth: 4, |
272 | 272 | }; |
273 | 273 | ``` |
274 | 274 |
|
|
397 | 397 |
|
398 | 398 | ```javascript |
399 | 399 | // bad |
400 | | - const name = "Bob Parr"; |
| 400 | + const name = "Capt. Janeway"; |
401 | 401 |
|
402 | 402 | // good |
403 | | - const name = 'Bob Parr'; |
| 403 | + const name = 'Capt. Janeway'; |
404 | 404 | ``` |
405 | 405 |
|
406 | 406 | - Strings longer than 80 characters should be written across multiple lines using string concatenation. |
|
809 | 809 | sum === 15; |
810 | 810 | ``` |
811 | 811 |
|
812 | | - - Don't use generators. |
| 812 | + - Don't use generators for now. |
813 | 813 |
|
814 | 814 | > Why? They don't transpile well to ES5. |
815 | 815 |
|
|
823 | 823 | ```javascript |
824 | 824 | const luke = { |
825 | 825 | jedi: true, |
826 | | - age: 28 |
| 826 | + age: 28, |
827 | 827 | }; |
828 | 828 |
|
829 | 829 | // bad |
|
838 | 838 | ```javascript |
839 | 839 | const luke = { |
840 | 840 | jedi: true, |
841 | | - age: 28 |
| 841 | + age: 28, |
842 | 842 | }; |
843 | 843 |
|
844 | 844 | function getProp(prop) { |
|
1225 | 1225 | - Use `// FIXME:` to annotate problems. |
1226 | 1226 |
|
1227 | 1227 | ```javascript |
1228 | | - function Calculator() { |
| 1228 | + class Calculator { |
| 1229 | + constructor() { |
| 1230 | + // FIXME: shouldn't use a global here |
| 1231 | + total = 0; |
1229 | 1232 |
|
1230 | | - // FIXME: shouldn't use a global here |
1231 | | - total = 0; |
1232 | | -
|
1233 | | - return this; |
| 1233 | + return this; |
| 1234 | + } |
1234 | 1235 | } |
1235 | 1236 | ``` |
1236 | 1237 |
|
1237 | 1238 | - Use `// TODO:` to annotate solutions to problems. |
1238 | 1239 |
|
1239 | 1240 | ```javascript |
1240 | | - function Calculator() { |
1241 | | -
|
1242 | | - // TODO: total should be configurable by an options param |
1243 | | - this.total = 0; |
| 1241 | + class Calculator { |
| 1242 | + constructor() { |
| 1243 | + // TODO: total should be configurable by an options param |
| 1244 | + this.total = 0; |
1244 | 1245 |
|
1245 | | - return this; |
| 1246 | + return this; |
| 1247 | + } |
1246 | 1248 | } |
1247 | 1249 | ``` |
1248 | 1250 |
|
|
1412 | 1414 |
|
1413 | 1415 | // bad |
1414 | 1416 | const obj = { |
1415 | | - foo: function() { |
| 1417 | + foo() { |
| 1418 | + }, |
| 1419 | + bar() { |
1416 | 1420 | }, |
1417 | | - bar: function() { |
1418 | | - } |
1419 | 1421 | }; |
1420 | 1422 | return obj; |
1421 | 1423 |
|
1422 | 1424 | // good |
1423 | 1425 | const obj = { |
1424 | | - foo: function() { |
| 1426 | + foo() { |
1425 | 1427 | }, |
1426 | 1428 |
|
1427 | | - bar: function() { |
1428 | | - } |
| 1429 | + bar() { |
| 1430 | + }, |
1429 | 1431 | }; |
1430 | 1432 |
|
1431 | 1433 | return obj; |
|
1450 | 1452 | const story = [ |
1451 | 1453 | once, |
1452 | 1454 | upon, |
1453 | | - aTime |
| 1455 | + aTime, |
1454 | 1456 | ]; |
1455 | 1457 |
|
1456 | 1458 | // bad |
1457 | 1459 | const hero = { |
1458 | | - firstName: 'Bob' |
1459 | | - , lastName: 'Parr' |
1460 | | - , heroName: 'Mr. Incredible' |
1461 | | - , superPower: 'strength' |
| 1460 | + firstName: 'Ada' |
| 1461 | + , lastName: 'Lovelace' |
| 1462 | + , birthYear: 1815 |
| 1463 | + , superPower: 'computers' |
1462 | 1464 | }; |
1463 | 1465 |
|
1464 | 1466 | // good |
1465 | 1467 | const hero = { |
1466 | | - firstName: 'Bob', |
1467 | | - lastName: 'Parr', |
1468 | | - heroName: 'Mr. Incredible', |
1469 | | - superPower: 'strength' |
| 1468 | + firstName: 'Ada', |
| 1469 | + lastName: 'Lovelace', |
| 1470 | + birthYear: 1815, |
| 1471 | + superPower: 'computers', |
1470 | 1472 | }; |
1471 | 1473 | ``` |
1472 | 1474 |
|
|
1477 | 1479 | ```javascript |
1478 | 1480 | // bad - git diff without trailing comma |
1479 | 1481 | const hero = { |
1480 | | - firstName: 'Bob', |
1481 | | - - lastName: 'Parr' |
1482 | | - + lastName: 'Parr', |
1483 | | - + heroName: 'Mr. Incredible' |
| 1482 | + firstName: 'Florence', |
| 1483 | + - lastName: 'Nightingale' |
| 1484 | + + lastName: 'Nightingale', |
| 1485 | + + inventorOf: ['coxcomb graph', 'mordern nursing'] |
1484 | 1486 | } |
1485 | 1487 |
|
1486 | 1488 | // good - git diff with trailing comma |
1487 | 1489 | const hero = { |
1488 | | - firstName: 'Bob', |
1489 | | - lastName: 'Parr', |
1490 | | - + heroName: 'Mr. Incredible', |
| 1490 | + firstName: 'Florence', |
| 1491 | + lastName: 'Nightingale', |
| 1492 | + + inventorOf: ['coxcomb chart', 'mordern nursing'], |
1491 | 1493 | } |
1492 | 1494 |
|
1493 | 1495 | // bad |
1494 | 1496 | const hero = { |
1495 | | - firstName: 'Kevin', |
1496 | | - lastName: 'Flynn' |
| 1497 | + firstName: 'Dana', |
| 1498 | + lastName: 'Scully', |
| 1499 | + catchPhrase: 'Adventure is out there' |
1497 | 1500 | }; |
1498 | 1501 |
|
1499 | 1502 | const heroes = [ |
|
1503 | 1506 |
|
1504 | 1507 | // good |
1505 | 1508 | const hero = { |
1506 | | - firstName: 'Kevin', |
1507 | | - lastName: 'Flynn', |
| 1509 | + firstName: 'Dana', |
| 1510 | + lastName: 'Scully', |
| 1511 | + catchPhrase: 'Adventure is out there', |
1508 | 1512 | }; |
1509 | 1513 |
|
1510 | 1514 | const heroes = [ |
|
1660 | 1664 | } |
1661 | 1665 |
|
1662 | 1666 | const bad = new user({ |
1663 | | - name: 'nope' |
| 1667 | + name: 'nope', |
1664 | 1668 | }); |
1665 | 1669 |
|
1666 | 1670 | // good |
|
1671 | 1675 | } |
1672 | 1676 |
|
1673 | 1677 | const good = new User({ |
1674 | | - name: 'yup' |
| 1678 | + name: 'yup', |
1675 | 1679 | }); |
1676 | 1680 | ``` |
1677 | 1681 |
|
|
0 commit comments