Let me start by saying, there are a lot of terms. Have you gathered that yet? In programming, just like in your other classes, there are a lot of words that we have to know to be successful. I am one hundred percent sure, you all could start talking about some graphic design terms, and I would be somewhat lost. However, once we learn the terminology, then the subject matter becomes much less scary.
When it comes to OOP, there are two fundamental aspects. They are Classes and Objects.
Let’s start again with what. What are classes, and what are objects?
Why do we use classes and objects
We use classes to represent something generically and specific objects to describe the actual items.
What does that mean? Let’s look at an example:
Let’s take a person as an example. What do all people have?
That is our class. If what I specified above is the generic template, then a specific instance or object is:
And we can create more people from the same class. The beautiful part is that we don’t have to create multiple classes, just numerous objects from the same class.
We will dig into Classes and Object in more detail in the next section.
An object or class property, also known as an attribute, is a piece of data used to describe the resulting object.
In our previous example, the properties were Eye color, Number of Legs, Number of Arms, Hair Color, Height, Weight. All of these things described our person.
When we created the object, they all had values like Blue eyes, two legs, etc.
An object or class method is a function. You can think of it as “It does stuff.” So, any function you create, which you have done already, does stuff for you.
new
)When we create a new object from a class, we are instantiating the new object.
As we will see throughout this week’s content, to create a new instance of a class, we will use the JavaScript keyword new
.
A potentially confusing idea is the reference to “specific instances” of an object. When referring to a specific instance of an object, or when referring to an object’s instance (from within the object), we will use the term this.
JavaScript uses the this
keyword throughout the language. Using this
can be very confusing (hence why it has remained anonymous until now). Before we dive deep into this
, try and accept that this
refers to a variable in the object itself.