@@ -582,7 +582,7 @@ would be much better to just use ES2015/ES6 classes and simply extend the `Array
582582
583583** Bad:**
584584``` javascript
585- Array .prototype .diff = function (comparisonArray ) {
585+ Array .prototype .diff = function diff (comparisonArray ) {
586586 const values = [];
587587 const hash = {};
588588
@@ -972,7 +972,7 @@ const Employee = function(name) {
972972 this .name = name;
973973}
974974
975- Employee .prototype .getName = function () {
975+ Employee .prototype .getName = function getName () {
976976 return this .name ;
977977}
978978
@@ -984,15 +984,11 @@ console.log('Employee name: ' + employee.getName()); // Employee name: undefined
984984
985985** Good** :
986986``` 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+ };
996992
997993const employee = new Employee (' John Doe' );
998994console .log (' Employee name: ' + employee .getName ()); // Employee name: John Doe
@@ -1278,7 +1274,7 @@ class DOMTraverser {
12781274
12791275const $ = new DOMTraverser ({
12801276 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.
12821278 // ...
12831279});
12841280
@@ -1312,7 +1308,7 @@ class DOMTraverser {
13121308const $ = new DOMTraverser ({
13131309 rootNode: document .getElementsByTagName (' body' ),
13141310 options: {
1315- animationModule : function () {}
1311+ animationModule () {}
13161312 }
13171313});
13181314```
@@ -1429,7 +1425,7 @@ const Animal = function(age) {
14291425 this .age = age;
14301426};
14311427
1432- Animal .prototype .move = function () {};
1428+ Animal .prototype .move = function move () {};
14331429
14341430const Mammal = function (age , furColor ) {
14351431 if (! (this instanceof Mammal)) {
@@ -1442,7 +1438,7 @@ const Mammal = function(age, furColor) {
14421438
14431439Mammal .prototype = Object .create (Animal .prototype );
14441440Mammal .prototype .constructor = Mammal;
1445- Mammal .prototype .liveBirth = function () {};
1441+ Mammal .prototype .liveBirth = function liveBirth () {};
14461442
14471443const Human = function (age , furColor , languageSpoken ) {
14481444 if (! (this instanceof Human)) {
@@ -1455,7 +1451,7 @@ const Human = function(age, furColor, languageSpoken) {
14551451
14561452Human .prototype = Object .create (Mammal .prototype );
14571453Human .prototype .constructor = Human;
1458- Human .prototype .speak = function () {};
1454+ Human .prototype .speak = function speak () {};
14591455```
14601456
14611457** Good:**
@@ -1663,8 +1659,8 @@ or refactoring an existing one.
16631659``` javascript
16641660const assert = require (' assert' );
16651661
1666- describe (' MakeMomentJSGreatAgain' , function () {
1667- it (' handles date boundaries' , function () {
1662+ describe (' MakeMomentJSGreatAgain' , () => {
1663+ it (' handles date boundaries' , () => {
16681664 let date;
16691665
16701666 date = new MakeMomentJSGreatAgain (' 1/1/2015' );
@@ -1686,20 +1682,20 @@ describe('MakeMomentJSGreatAgain', function() {
16861682``` javascript
16871683const assert = require (' assert' );
16881684
1689- describe (' MakeMomentJSGreatAgain' , function () {
1690- it (' handles 30-day months' , function () {
1685+ describe (' MakeMomentJSGreatAgain' , () => {
1686+ it (' handles 30-day months' , () => {
16911687 const date = new MakeMomentJSGreatAgain (' 1/1/2015' );
16921688 date .addDays (30 );
16931689 date .shouldEqual (' 1/31/2015' );
16941690 });
16951691
1696- it (' handles leap year' , function () {
1692+ it (' handles leap year' , () => {
16971693 const date = new MakeMomentJSGreatAgain (' 2/1/2016' );
16981694 date .addDays (28 );
16991695 assert .equal (' 02/29/2016' , date);
17001696 });
17011697
1702- it (' handles non-leap year' , function () {
1698+ it (' handles non-leap year' , () => {
17031699 const date = new MakeMomentJSGreatAgain (' 2/1/2015' );
17041700 date .addDays (28 );
17051701 assert .equal (' 03/01/2015' , date);
@@ -1734,13 +1730,13 @@ require('request').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin', (req
17341730** Good** :
17351731``` javascript
17361732require (' request-promise' ).get (' https://en.wikipedia.org/wiki/Robert_Cecil_Martin' )
1737- .then (function (response ) {
1733+ .then ((response ) => {
17381734 return require (' fs-promise' ).writeFile (' article.html' , response);
17391735 })
1740- .then (function () {
1736+ .then (() => {
17411737 console .log (' File written' );
17421738 })
1743- .catch (function (err ) {
1739+ .catch ((err ) => {
17441740 console .error (err);
17451741 })
17461742
@@ -1757,13 +1753,13 @@ today!
17571753** Bad:**
17581754``` javascript
17591755require (' request-promise' ).get (' https://en.wikipedia.org/wiki/Robert_Cecil_Martin' )
1760- .then (function (response ) {
1756+ .then ((response ) => {
17611757 return require (' fs-promise' ).writeFile (' article.html' , response);
17621758 })
1763- .then (function () {
1759+ .then (() => {
17641760 console .log (' File written' );
17651761 })
1766- .catch (function (err ) {
1762+ .catch ((err ) => {
17671763 console .error (err);
17681764 })
17691765
0 commit comments