What is a constructor in programming?

703 viewsOtherTechnology

I am still trying to wrap my head around the concept I learned in class a while ago. We learned briefly about constructors in JavaScript. Can someone please ELI5? Thank you!

In: Technology

18 Answers

Anonymous 0 Comments

A constructor is a subroutine that returns a new object.  An object in this context  is a bundle of data that represents an abstraction of something.  Some constructors just allocate memory and populate it with default values.  Others might register the new object in a master list or other controller object, or could even initialize hardware in the real world. 

 The opposite is a destructor, which accepts an object and de-allocates it and does anything else needed to maintain class distance of the overall program’s memory.  That might include deleting references to the object from elsewhere, or even sending command sequences out to actual hardware.

You are viewing 1 out of 18 answers, click here to view all answers.