Constructor Functions: A constructor is a special type of subroutine called to create an object it prepares the new object for use, often accepting arguments that the constructor uses to set required member variables, if I decided to go deeper into the meaning am afraid I would deviate from what exactly this article is meant for (the constructor or classes). The constructor function is ES5 it way of defining object and adding method with new functions.
Classes: Is template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes unlike the traditional method of adding new functions to a constructor in ES5; they have some syntax and semantics that are not shared with ES5. Classes are also known as syntactic sugar it made inheritance easy and other sync ideas of programming. It was easier to initialized object and structure data. It used a keyword Class to start before instantiating an object and it has a default constructor method in it.
Over the few weeks I had struggle on what ideal way to learn about constructor I initially started using constructor functions before I started using classes, I had to admit the difference is very clear and even if some argue they are the same I decided to stop using constructor functions and started learning classes and spend some time using it. ES6 is new and without further ado anything new is for the best, hence I strongly advice myself that since it a new method it gotta be better than using the former ES5 method. Off the record I advice myself to find out more and not to seemly assume and never understand why.
“Not totally. Classes now have support for truly private properties; you don’t get that with constructor functions”. (The code Genin)
more over “Class is more OOP (Object Oriented Programming) for instance if you write other OOP based languages like vue js” (Tomisinteazer) I suddenly drop the idea of ES6 is better than ES5 but rather saw in a different light that it more about productivity and clean code.
“In a more different light functions and classes isn’t totally the same because there is set and get method” (The Code Genn).
Another heat was drop on that comment “get and set you can always write it yourself it syntactic sugar” (Tomisinteazer). The chat was hot and mild but the ideas kept on coming and it was pointing to one direction Learn both.
“Prototypal inheritance is what the class syntax does under the hood. It just make it look like class based inheritance of other languages. I don’t know how class based inheritance works by the way, more like a shallow clone of object”. (Debo).