⇧
vadnica-logo
My Services About the Project Telegram O meni O meni

JavaScript Constructor

The constructor method is a special method that must have exactly the name constructor() and is executed automatically when a new object is created. It is used to initialize object properties. If we do not define a constructor method, JavaScript will add an empty constructor method. A class cannot have more than one constructor() method, because it will cause a SyntaxError. If we want to create class inheritance, we must use the extends keyword. The super() method refers to the parent class. By calling the super() method in the constructor method, we call the parent constructor method and gain access to parent properties and methods. The constructor property returns the function that creates the prototype. For JavaScript arrays, the property returns as function Object() { [native code] }.

EXAMPLE
RESULT