@@ -582,7 +582,7 @@ would be much better to just use ES2015/ES6 classes and simply extend the `Array
|
582 | 582 |
|
583 | 583 | **Bad:**
|
584 | 584 | ```javascript
|
585 |
| -Array..diff = function(comparisonArray) { |
| 585 | +Array..diff = function diff(comparisonArray) { |
586 | 586 | const values = [];
|
587 | 587 | const hash = {};
|
588 | 588 |
|
@@ -972,7 +972,7 @@ const Employee = function(name) {
|
972 | 972 | this.name = name;
|
973 | 973 | }
|
974 | 974 |
|
975 |
| -Employee..getName = function() { |
| 975 | +Employee..getName = function getName() { |
976 | 976 | return this.name;
|
977 | 977 | }
|
978 | 978 |
|
@@ -984,15 +984,11 @@ console.log('Employee name: ' + employee.getName()); // Employee name: undefined
|
984 | 984 |
|
985 | 985 | **Good**:
|
986 | 986 | ```javascript
|
987 |
| -const Employee = (function() { |
988 |
| -function Employee(name) { |
989 |
| -this.getName = function() { |
990 |
| -return name; |
991 |
| -}; |
992 |
| -} |
993 |
| - |
994 |
| -return Employee; |
995 |
| -}()); |
| 987 | +const Employee = function (name) { |
| 988 | +this.getName = function getName() { |
| 989 | +return name; |
| 990 | +}; |
| 991 | +}; |
996 | 992 |
|
997 | 993 | const employee = new Employee('John Doe');
|
998 | 994 | console.log('Employee name: ' + employee.getName()); // Employee name: John Doe
|
@@ -1278,7 +1274,7 @@ class DOMTraverser {
|
1278 | 1274 |
|
1279 | 1275 | const $ = new DOMTraverser({
|
1280 | 1276 | rootNode: document.getElementsByTagName('body'),
|
1281 |
| -animationModule: function() {} // Most of the time, we won't need to animate when traversing. |
| 1277 | +animationModule() {} // Most of the time, we won't need to animate when traversing. |
1282 | 1278 | // ...
|
1283 | 1279 | });
|
1284 | 1280 |
|
@@ -1312,7 +1308,7 @@ class DOMTraverser {
|
1312 | 1308 | const $ = new DOMTraverser({
|
1313 | 1309 | rootNode: document.getElementsByTagName('body'),
|
1314 | 1310 | options: {
|
1315 |
| -animationModule: function() {} |
| 1311 | +animationModule() {} |
1316 | 1312 | }
|
1317 | 1313 | });
|
1318 | 1314 | ```
|
@@ -1429,7 +1425,7 @@ const Animal = function(age) {
|
1429 | 1425 | this.age = age;
|
1430 | 1426 | };
|
1431 | 1427 |
|
1432 |
| -Animal..move = function() {}; |
| 1428 | +Animal..move = function move() {}; |
1433 | 1429 |
|
1434 | 1430 | const Mammal = function(age, furColor) {
|
1435 | 1431 | if (!(this instanceof Mammal)) {
|
@@ -1442,7 +1438,7 @@ const Mammal = function(age, furColor) {
|
1442 | 1438 |
|
1443 | 1439 | Mammal. = Object.create(Animal.);
|
1444 | 1440 | Mammal..constructor = Mammal;
|
1445 |
| -Mammal..liveBirth = function() {}; |
| 1441 | +Mammal..liveBirth = function liveBirth() {}; |
1446 | 1442 |
|
1447 | 1443 | const Human = function(age, furColor, languageSpoken) {
|
1448 | 1444 | if (!(this instanceof Human)) {
|
@@ -1455,7 +1451,7 @@ const Human = function(age, furColor, languageSpoken) {
|
1455 | 1451 |
|
1456 | 1452 | Human. = Object.create(Mammal.);
|
1457 | 1453 | Human..constructor = Human;
|
1458 |
| -Human..speak = function() {}; |
| 1454 | +Human..speak = function speak() {}; |
1459 | 1455 | ```
|
1460 | 1456 |
|
1461 | 1457 | **Good:**
|
@@ -1663,8 +1659,8 @@ or refactoring an existing one.
|
1663 | 1659 | ```javascript
|
1664 | 1660 | const assert = require('assert');
|
1665 | 1661 |
|
1666 |
| -describe('MakeMomentJSGreatAgain', function() { |
1667 |
| -it('handles date boundaries', function() { |
| 1662 | +describe('MakeMomentJSGreatAgain', () => { |
| 1663 | +it('handles date boundaries', () => { |
1668 | 1664 | let date;
|
1669 | 1665 |
|
1670 | 1666 | date = new MakeMomentJSGreatAgain('1/1/2015');
|
@@ -1686,20 +1682,20 @@ describe('MakeMomentJSGreatAgain', function() {
|
1686 | 1682 | ```javascript
|
1687 | 1683 | const assert = require('assert');
|
1688 | 1684 |
|
1689 |
| -describe('MakeMomentJSGreatAgain', function() { |
1690 |
| -it('handles 30-day months', function() { |
| 1685 | +describe('MakeMomentJSGreatAgain', () => { |
| 1686 | +it('handles 30-day months', () => { |
1691 | 1687 | const date = new MakeMomentJSGreatAgain('1/1/2015');
|
1692 | 1688 | date.addDays(30);
|
1693 | 1689 | date.shouldEqual('1/31/2015');
|
1694 | 1690 | });
|
1695 | 1691 |
|
1696 |
| -it('handles leap year', function() { |
| 1692 | +it('handles leap year', () => { |
1697 | 1693 | const date = new MakeMomentJSGreatAgain('2/1/2016');
|
1698 | 1694 | date.addDays(28);
|
1699 | 1695 | assert.equal('02/29/2016', date);
|
1700 | 1696 | });
|
1701 | 1697 |
|
1702 |
| -it('handles non-leap year', function() { |
| 1698 | +it('handles non-leap year', () => { |
1703 | 1699 | const date = new MakeMomentJSGreatAgain('2/1/2015');
|
1704 | 1700 | date.addDays(28);
|
1705 | 1701 | assert.equal('03/01/2015', date);
|
@@ -1734,13 +1730,13 @@ require('request').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin', (req
|
1734 | 1730 | **Good**:
|
1735 | 1731 | ```javascript
|
1736 | 1732 | require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin')
|
1737 |
| -.then(function(response) { |
| 1733 | +.then((response) => { |
1738 | 1734 | return require('fs-promise').writeFile('article.html', response);
|
1739 | 1735 | })
|
1740 |
| -.then(function() { |
| 1736 | +.then(() => { |
1741 | 1737 | console.log('File written');
|
1742 | 1738 | })
|
1743 |
| -.catch(function(err) { |
| 1739 | +.catch((err) => { |
1744 | 1740 | console.error(err);
|
1745 | 1741 | })
|
1746 | 1742 |
|
@@ -1757,13 +1753,13 @@ today!
|
1757 | 1753 | **Bad:**
|
1758 | 1754 | ```javascript
|
1759 | 1755 | require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin')
|
1760 |
| -.then(function(response) { |
| 1756 | +.then((response) => { |
1761 | 1757 | return require('fs-promise').writeFile('article.html', response);
|
1762 | 1758 | })
|
1763 |
| -.then(function() { |
| 1759 | +.then(() => { |
1764 | 1760 | console.log('File written');
|
1765 | 1761 | })
|
1766 |
| -.catch(function(err) { |
| 1762 | +.catch((err) => { |
1767 | 1763 | console.error(err);
|
1768 | 1764 | })
|
1769 | 1765 |
|
|
0 commit comments