2.7 understanding classes
We learned about imports and exports another essential feature of the next generation JavaScript and that classes if you come in this programming language you may knoware already classes the classes are essentially planes for the objects in our case here for Javascript objects a class created with the word class and a class can have both properties of the methods the methods are simply functions attached to classes and properties are variables attached to classes you can say that we will use both in this course and then we will always explain what we are doing here
when we have such a property or method a class and instantiate like this with the new keyword and it may seem familiar to you if you have worked a little with JavaScript you may noticebe constructor functions and classes are sort of a more convenient way to create constructor functions in order to create javascript objects with classes as a plan
this is the idea and classes also support inheritance it means that you have another class that you inherit by taking all its properties and methods and potentially adding new properties and methods it might also seem to you as familiar you may noticebe prototypes looking at the ranking in new action ranked here I’m going to name it like this then you have the braces to mark the body of the class and now we can now start using the properties in its simplest form a property is added by adding a constructor that is a default function method you can add to any classes that will be executed each time you instant the class and the method is created with just the name of the method parentheses and then between braces and then there we can now configure the property with the word-this key and we can write this name is equal to Mathieu PrintMyName we could just output this not referring to the most name property we have created
we can now use this class to store an intense in a constant with a new person and then execute that-here if we click now We see Mathieu it’s as simple to use a class now I said that classes can also inherit we can create a human class and add a builder to it to define sex = man or woman of course if you want what you feel and now if no one being then it’s a word-key that extends a new human now we were from this property and this method printgender and we can also use both on the person in order to call a person printgender like that however before we succeed we will try it we will have a error that we must call the super-constructors in the derived class and this is important if you hear another class and implement the constructor what you don’t have to do
but if you are then you need to add this special super method into the builder it’s a word-key that simply executes the parent constructor to which you must of course correct yourself to reset the parent class so now you clearly see Matthew and Male obviously you can now enter your person class and still define sex here what is not 100% correct here but this is just to show that it works we now see that we print in women even though we still learn printgender here but it is extended by person in these are classes and classes are used by react to create its components at least this is one of the two ways to create components here is how you will see me using in this course and it is important to understand that classes are only plans for Javascript objects and that they are very comparable manufacturers or legacy and comparable to prototypes