JavaScript Classes

https://www.codecademy.com/courses/introduction-to-javascript/lessons/classes/exercises/methods?action=resume_content_item

How does the method (takeVacationDays(daysOff)) access the getter get (remainingVacationDays()) above? I thought you’d have to call the getter in the method to access the return value provided by the getter? This is step 6, the final step, in the exercise.

What makes you say it does? (it doesn’t)

Oh it’s accessing the property inthe constructor?

No, not that either.

It says in the code what it accesses.

(What does this refer to? (not the constructor))

No, it refers to the class Surgeon

It does not.
If it did, you could write:

Surgeon._remainingVacationDays, and that would be the same thing.
And it would be problematic if all surgeons shared vacation days. There’s only one Surgeon class, so that would be a bad place to store that information.

It refers to the parameters of the constructor?

Those no longer exist. That function has exited.

…to be fair that says a whole lot of not-relevant things before it gets to the point, the thing that is the whole point of this

When a function is called as a method of an object, its this is set to the object the method is called on.

Ya, which the object is described by the parameters of the constructor I thought

The arguments given to the constructor might describe the object, partially anyway. But they are not the object, and the object already exists at that point.

If you’re going to do things with your object, then you’ll probably want access to the object.

So where is the object, how is it referenced?

It’s referenced by the const surgeonCurry = new Surgeon(‘Curry’, ‘Cardiovascular’);

So, surgeonCurry is the name of the object in that case.

That’s even further in the future

this refers to the object

But how does the object even exist within the class until it is defined?

defined? are you talking about your variable? your variable isn’t the object, variables are names.

When you use the new operator with an object type

new sometype()

Then first an object is created based off a prototype, and then a constructor function gets called. When the constructor starts executing, it will have access to the object (how else would it be able to do things like setting properties on the object)

You can see this in your own constructor function. When your constructor “wants” to make changes to the object in question, it is using this to access the object.

‘this’ refers to an object, and that object has to have those two parameters within the constructor defined right because those are instance properties

Your object doesn’t have parameters (not sure that makes sense)

The values provided to your constructor are not part of the object, not unless you somehow bind them to a property of the object.

If you have an object and a bunch of values, then, sure, if you want, you can create properties on your object to refer to your values.

Your constructor has access to a bunch of values that it received.
And it has access to the object.
So if it wishes, it could do that.

oh you bind them with the this._name = name etc.