Skip to content

Commit f3f6261

Browse files
committed
correct using of this in examples
1 parent 907617b commit f3f6261

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

README.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ class Airplane {
741741
getCruisingAltitude() {
742742
switch (this.type) {
743743
case '777':
744-
return getMaxAltitude() - getPassengerCount();
744+
return this.getMaxAltitude() - this.getPassengerCount();
745745
case 'Air Force One':
746-
return getMaxAltitude();
746+
return this.getMaxAltitude();
747747
case 'Cessna':
748-
return getMaxAltitude() - getFuelExpenditure();
748+
return this.getMaxAltitude() - this.getFuelExpenditure();
749749
}
750750
}
751751
}
@@ -760,21 +760,21 @@ class Airplane {
760760
class Boeing777 extends Airplane {
761761
// ...
762762
getCruisingAltitude() {
763-
return getMaxAltitude() - getPassengerCount();
763+
return this.getMaxAltitude() - this.getPassengerCount();
764764
}
765765
}
766766

767767
class AirForceOne extends Airplane {
768768
// ...
769769
getCruisingAltitude() {
770-
return getMaxAltitude();
770+
return this.getMaxAltitude();
771771
}
772772
}
773773

774774
class Cessna extends Airplane {
775775
// ...
776776
getCruisingAltitude() {
777-
return getMaxAltitude() - getFuelExpenditure();
777+
return this.getMaxAltitude() - this.getFuelExpenditure();
778778
}
779779
}
780780
```
@@ -1006,12 +1006,12 @@ class UserSettings {
10061006
}
10071007

10081008
changeSettings(settings) {
1009-
if (this.verifyCredentials(user)) {
1009+
if (this.verifyCredentials()) {
10101010
// ...
10111011
}
10121012
}
10131013

1014-
verifyCredentials(user) {
1014+
verifyCredentials() {
10151015
// ...
10161016
}
10171017
}
@@ -1406,35 +1406,35 @@ classes until you find yourself needing larger and more complex objects.
14061406
**Bad:**
14071407
```javascript
14081408
const Animal = function(age) {
1409-
if (!(this instanceof Animal)) {
1410-
throw new Error("Instantiate Animal with `new`");
1411-
}
1409+
if (!(this instanceof Animal)) {
1410+
throw new Error("Instantiate Animal with `new`");
1411+
}
14121412

1413-
this.age = age;
1413+
this.age = age;
14141414
};
14151415

14161416
Animal.prototype.move = function() {};
14171417

14181418
const Mammal = function(age, furColor) {
1419-
if (!(this instanceof Mammal)) {
1420-
throw new Error("Instantiate Mammal with `new`");
1421-
}
1419+
if (!(this instanceof Mammal)) {
1420+
throw new Error("Instantiate Mammal with `new`");
1421+
}
14221422

1423-
Animal.call(this, age);
1424-
this.furColor = furColor;
1423+
Animal.call(this, age);
1424+
this.furColor = furColor;
14251425
};
14261426

14271427
Mammal.prototype = Object.create(Animal.prototype);
14281428
Mammal.prototype.constructor = Mammal;
14291429
Mammal.prototype.liveBirth = function() {};
14301430

14311431
const Human = function(age, furColor, languageSpoken) {
1432-
if (!(this instanceof Human)) {
1433-
throw new Error("Instantiate Human with `new`");
1434-
}
1432+
if (!(this instanceof Human)) {
1433+
throw new Error("Instantiate Human with `new`");
1434+
}
14351435

1436-
Mammal.call(this, age, furColor);
1437-
this.languageSpoken = languageSpoken;
1436+
Mammal.call(this, age, furColor);
1437+
this.languageSpoken = languageSpoken;
14381438
};
14391439

14401440
Human.prototype = Object.create(Mammal.prototype);
@@ -1445,29 +1445,29 @@ Human.prototype.speak = function() {};
14451445
**Good:**
14461446
```javascript
14471447
class Animal {
1448-
constructor(age) {
1449-
this.age = age;
1450-
}
1448+
constructor(age) {
1449+
this.age = age;
1450+
}
14511451

1452-
move() {}
1452+
move() { /* ... */ }
14531453
}
14541454

14551455
class Mammal extends Animal {
1456-
constructor(age, furColor) {
1457-
super(age);
1458-
this.furColor = furColor;
1459-
}
1456+
constructor(age, furColor) {
1457+
super(age);
1458+
this.furColor = furColor;
1459+
}
14601460

1461-
liveBirth() {}
1461+
liveBirth() { /* ... */ }
14621462
}
14631463

14641464
class Human extends Mammal {
1465-
constructor(age, furColor, languageSpoken) {
1466-
super(age, furColor);
1467-
this.languageSpoken = languageSpoken;
1468-
}
1465+
constructor(age, furColor, languageSpoken) {
1466+
super(age, furColor);
1467+
this.languageSpoken = languageSpoken;
1468+
}
14691469

1470-
speak() {}
1470+
speak() { /* ... */ }
14711471
}
14721472
```
14731473
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)