FAQ: Classes - Inheritance V

#1

This community-built FAQ covers the “Inheritance V” exercise from the lesson “Classes”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Inheritance V

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#2

/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:25
get certifications()
^

RangeError: Maximum call stack size exceeded
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:25:21)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)
at Nurse.get certifications [as certifications] (/home/ccuser/workspace/learn-javascript-classes-classes-inheritance-v/main.js:27:44)

I have got the above message on the output screen although the code run fine. Can someone explain about this?

#4

It’s like getters must be made before corresponding methods can work.

#5

console.log(nurseOlynyk._certifications[2]) of genetics
This line of code generates the correct answer to the activity on screen 10 but doesn’t lead to correct response on webpage.

#6

nurseOlynyk.addCertification(‘Genetics’);
console.log(nurseOlynyk.certifications); //[ ‘Trauma’, ‘Pediatrics’, ‘Genetics’ ]

#7

No need to put the underscore because we are pushing the new string into the parameter, certifications.

#8

Thanks, i’ll may check into that later. Having to deal with some practical stuffs/other stuff so haven’t look back into Javascript on CodeAcademy in a few weeks. That sounds like a good catch.

#9

Don’t be mislead into thinking the underscores are of no particular significance. Architecturally they are vitally important and cannot for a second be written off.

We’re in a different domain once setters and getters are introduced. Forget that we can sort of do the same thing without them. With them we have another level of functionality. Not just another level, a whole universe of inspection, validation, composition, reporting, &c. Not the sort of thing we would expect to find in a property definition.

Consider,

 this.prop = value;
 // ...
 get prop () {
     return this._prop;
 }
 set prop (value) {
     // validate value
     this._prop = value;
 }

We’ve essentially created a backing variable using the very setter intended to work with one. The getter will now work as expected.

Perhaps you can explain why we cannot perform both operations at once? There seems to be some restriction in place. Any ideas?


Proof the setter is run…

 > class a {
     constructor(value) {
       this.prop = value;
     }
     get prop () {
       return this._prop;
     }
     set prop (value) {
       // validate value
       this._prop = value;
    }
  }
<- undefined
 > b = new a('funny')
<- > a {_prop: "funny"}
 > b._prop
<- "funny"

At this point we confirm the endpoint. Now we want to validate the data before it reaches the endpoint.

#10

I wasn’t writing off the underscores. The comment of pratical was in reference to needing to deal with some real life issues before getting back to codeacademy problem and finding a solution. Thanks for your assistance.

1 Like