Javascript does not support real classes like Java, C# and other languages. But pseudo classes can be defined in js. The tools for doing this are constructors and prototype objects. First introduce the constructor in js.
The syntax for creating objects in Javascript is to follow the new operator followed by a function call. For example,
var obj = {};
var date = Date.call(obj);
The function of the constructor is to initialize a newly created object and set the properties of the object before using it. If you define your own constructor, you only need to write a function that adds attributes to this. The following code defines a constructor:
var rect = new Rectange(4,8);
The return value of the constructor
Constructors in Javascript usually have no return value. However, functions are allowed to return values. If a constructor has a return value, the returned object becomes the value of the new expression. In this case, the object used as this will be discarded.