Classes & Object
According to MDN Web Docs, classes are are a template for creating objects. They encapsulate data with code to work on that data. Classes are considered “special” functions, and just as you define regular functions, classes have expressions and declarations. Class declaration is simple and straight forward, where you use the “class” keyword along with the name of the class (i.e. Engineer). Below is how we would go about declaring a class.
Class expression is just another way to define a class. They can be named or unnamed. If we leave it unnamed, it would just refer back the original name we gave the class.
Setting up our classes is like creating a template or blueprint for our future objects. By using the constructor method we are able to create properties for the class. In the example above, we are able to create the name, favorite language and number properties for the engineer class. With the properties set in place, we can now create objects with property values.
When “this” is used alone in the a global context or in a function, the owner is the global object. Meaning “this” is referring to its owner, the global object.
When “this” is used in a method, it is referring to the owner of the method.