@@ -744,11 +744,11 @@ class Airplane {
|
744 | 744 | getCruisingAltitude() {
|
745 | 745 | switch (this.type) {
|
746 | 746 | case '777':
|
747 |
| -return getMaxAltitude() - getPassengerCount(); |
| 747 | +return this.getMaxAltitude() - this.getPassengerCount(); |
748 | 748 | case 'Air Force One':
|
749 |
| -return getMaxAltitude(); |
| 749 | +return this.getMaxAltitude(); |
750 | 750 | case 'Cessna':
|
751 |
| -return getMaxAltitude() - getFuelExpenditure(); |
| 751 | +return this.getMaxAltitude() - this.getFuelExpenditure(); |
752 | 752 | }
|
753 | 753 | }
|
754 | 754 | }
|
@@ -763,21 +763,21 @@ class Airplane {
|
763 | 763 | class Boeing777 extends Airplane {
|
764 | 764 | // ...
|
765 | 765 | getCruisingAltitude() {
|
766 |
| -return getMaxAltitude() - getPassengerCount(); |
| 766 | +return this.getMaxAltitude() - this.getPassengerCount(); |
767 | 767 | }
|
768 | 768 | }
|
769 | 769 |
|
770 | 770 | class AirForceOne extends Airplane {
|
771 | 771 | // ...
|
772 | 772 | getCruisingAltitude() {
|
773 |
| -return getMaxAltitude(); |
| 773 | +return this.getMaxAltitude(); |
774 | 774 | }
|
775 | 775 | }
|
776 | 776 |
|
777 | 777 | class Cessna extends Airplane {
|
778 | 778 | // ...
|
779 | 779 | getCruisingAltitude() {
|
780 |
| -return getMaxAltitude() - getFuelExpenditure(); |
| 780 | +return this.getMaxAltitude() - this.getFuelExpenditure(); |
781 | 781 | }
|
782 | 782 | }
|
783 | 783 | ```
|
@@ -1009,12 +1009,12 @@ class UserSettings {
|
1009 | 1009 | }
|
1010 | 1010 |
|
1011 | 1011 | changeSettings(settings) {
|
1012 |
| -if (this.verifyCredentials(user)) { |
| 1012 | +if (this.verifyCredentials()) { |
1013 | 1013 | // ...
|
1014 | 1014 | }
|
1015 | 1015 | }
|
1016 | 1016 |
|
1017 |
| -verifyCredentials(user) { |
| 1017 | +verifyCredentials() { |
1018 | 1018 | // ...
|
1019 | 1019 | }
|
1020 | 1020 | }
|
@@ -1410,35 +1410,35 @@ classes until you find yourself needing larger and more complex objects.
|
1410 | 1410 | **Bad:**
|
1411 | 1411 | ```javascript
|
1412 | 1412 | const Animal = function(age) {
|
1413 |
| -if (!(this instanceof Animal)) { |
1414 |
| -throw new Error("Instantiate Animal with `new`"); |
1415 |
| -} |
| 1413 | +if (!(this instanceof Animal)) { |
| 1414 | +throw new Error("Instantiate Animal with `new`"); |
| 1415 | +} |
1416 | 1416 |
|
1417 |
| -this.age = age; |
| 1417 | +this.age = age; |
1418 | 1418 | };
|
1419 | 1419 |
|
1420 | 1420 | Animal..move = function() {};
|
1421 | 1421 |
|
1422 | 1422 | const Mammal = function(age, furColor) {
|
1423 |
| -if (!(this instanceof Mammal)) { |
1424 |
| -throw new Error("Instantiate Mammal with `new`"); |
1425 |
| -} |
| 1423 | +if (!(this instanceof Mammal)) { |
| 1424 | +throw new Error("Instantiate Mammal with `new`"); |
| 1425 | +} |
1426 | 1426 |
|
1427 |
| -Animal.call(this, age); |
1428 |
| -this.furColor = furColor; |
| 1427 | +Animal.call(this, age); |
| 1428 | +this.furColor = furColor; |
1429 | 1429 | };
|
1430 | 1430 |
|
1431 | 1431 | Mammal. = Object.create(Animal.);
|
1432 | 1432 | Mammal..constructor = Mammal;
|
1433 | 1433 | Mammal..liveBirth = function() {};
|
1434 | 1434 |
|
1435 | 1435 | const Human = function(age, furColor, languageSpoken) {
|
1436 |
| -if (!(this instanceof Human)) { |
1437 |
| -throw new Error("Instantiate Human with `new`"); |
1438 |
| -} |
| 1436 | +if (!(this instanceof Human)) { |
| 1437 | +throw new Error("Instantiate Human with `new`"); |
| 1438 | +} |
1439 | 1439 |
|
1440 |
| -Mammal.call(this, age, furColor); |
1441 |
| -this.languageSpoken = languageSpoken; |
| 1440 | +Mammal.call(this, age, furColor); |
| 1441 | +this.languageSpoken = languageSpoken; |
1442 | 1442 | };
|
1443 | 1443 |
|
1444 | 1444 | Human. = Object.create(Mammal.);
|
@@ -1449,29 +1449,29 @@ Human..speak = function() {};
|
1449 | 1449 | **Good:**
|
1450 | 1450 | ```javascript
|
1451 | 1451 | class Animal {
|
1452 |
| -constructor(age) { |
1453 |
| -this.age = age; |
1454 |
| -} |
| 1452 | +constructor(age) { |
| 1453 | +this.age = age; |
| 1454 | +} |
1455 | 1455 |
|
1456 |
| -move() {} |
| 1456 | +move() { /* ... */ } |
1457 | 1457 | }
|
1458 | 1458 |
|
1459 | 1459 | class Mammal extends Animal {
|
1460 |
| -constructor(age, furColor) { |
1461 |
| -super(age); |
1462 |
| -this.furColor = furColor; |
1463 |
| -} |
| 1460 | +constructor(age, furColor) { |
| 1461 | +super(age); |
| 1462 | +this.furColor = furColor; |
| 1463 | +} |
1464 | 1464 |
|
1465 |
| -liveBirth() {} |
| 1465 | +liveBirth() { /* ... */ } |
1466 | 1466 | }
|
1467 | 1467 |
|
1468 | 1468 | class Human extends Mammal {
|
1469 |
| -constructor(age, furColor, languageSpoken) { |
1470 |
| -super(age, furColor); |
1471 |
| -this.languageSpoken = languageSpoken; |
1472 |
| -} |
| 1469 | +constructor(age, furColor, languageSpoken) { |
| 1470 | +super(age, furColor); |
| 1471 | +this.languageSpoken = languageSpoken; |
| 1472 | +} |
1473 | 1473 |
|
1474 |
| -speak() {} |
| 1474 | +speak() { /* ... */ } |
1475 | 1475 | }
|
1476 | 1476 | ```
|
1477 | 1477 | **[⬆ back to top](#table-of-contents)**
|
|
0 commit comments