Every object prototype in JavaScript comes with a constructor method. The constructor method is the constructor function used to create the object.
For instance, we can turn a number into a string using the String constructor
String(2) === "2";
we can also do
"".constructor(2) === "2"
This works the same because the string's "constructor" points to the String constructor function.
Classes in JavaScript aren't classes as they exist in languages like Java or Ruby since JavaScript uses a prototypal inheritance system. So classes in JavaScript are just sugar syntax for plain constructor functions. This allows developers to take advantage of some OOP features of JavaScript without needing to know about many of the nuances about how its inheritance system works.
So the following:
function Cat (name,color){
this.name = name;
this.color = color;
}
Cat.prototype.speak = function(){
console.log("Meow");
}
Is effectively the same as
class Cat {
constructor(name,color){
this.name = name;
this.color = color;
}
speak(){
console.log("Meow");
}
}
Both can be instantiated using the new keyword
new Cat("Mittens", "black");
The "constructor" as described in the class example points to the underlying JavaScript constructor function. Remember that "class" in JavaScript is just a friendly wrapper around a constructor function that makes using it more similar to using classes in other languages.
When working with a class you'd use the "constructor" method to set some values directly to the object that will be created, rather than on its prototype. The prototype is an object common to all objects created with a class/constructor, that's used to share functionality between them.
Catitself. It is not a method.