The class
Chronometer
contains functions called
getMinutes
,
getSeconds
,
computeTwoDigitNumber
, and
split
.
These act upon the current instance of the class when they are called, and in your
split
function they are called on the
current instcne, called
this
. Inside a class,
this
always refers to the current instance of that class.
It's similar to cars: I have MyCar, you have YourCar. Those are separate instances of teh class Car and you already know that MyCar is not the same as YourCar - MyCar is a black Mercedes, YourCar is a a green Ford.
But if we refer to "this car" it could be either, and asking the question "What colour is this car?" will give us different results depending on which actual vehicle we are pointing at.
In car terms,
this
always references the current instance of a car and the questions we ask, the actions we take, the places we drive to are independent of which physical car we are talking about:
this.DriveTo("THE SHOPS")
is the same for YourCar as it is for MyCar.
The
this
keyword does the same thing in javascript: it says "call this function / access this value / change this detail" on the current class instance.
Make sense now?