We introduced object oriented programming previously. This programming methodology, of course, is based on objects. But what are objects, exactly?
At some point during the global effort made by programmers to help themselves create better programs, faster, more efficiently and all, the idea came to introduce this concept of objects.
In object oriented programming, you define a set of classes, or types of objects.
An object is an instance of a class, and it contains both code and data. The data is abstracted away in to the object, and the object is responsible for providing methods (which are functions attached to an object) to manipulate this data.
Say you have a Dog class. You can create a
myDog object by instantiating a new Dog:
const myDog = new Dog()
Roger is my dog’s name, so I can say so using
myDog.name = 'Roger'
A dog has an age:
myDog.age = 7
and we’ll have ways to retrieve this data.
Here I defined public properties. In general, classes offer public and private properties. Private properties allow to encapsulate data, and only let it be accessed using methods that you define.