Back to Content

Constructor

files/en-us/glossary/constructor/index.md

latest1.0 KB
Original Source

A constructor is a specialized {{glossary("function")}} that generates {{glossary("object", "objects")}} with the same shape and behavior. The constructor initializes this object with some data specific to the object. The concept of a constructor can be applied to most {{glossary("OOP","object-oriented programming")}} languages.

In {{glossary("JavaScript")}}, a constructor is usually declared within a class, but it can also be declared as a function. In fact, any function that can be called with the new operator is a constructor.

See also