What is a constructor in programming?

806 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

Crash course Object Oriented Programming: A class describes a type, like “Dog” or “Person”. An object is an instance of that type, like “Fido” is an object of type “Dog”. A method is a function defined as part of the class, and called on an object. For example, “feed()” might be method of “Dog” and you can then call “Fido.feed()” to feed Fido the Dog. 

Ok, with that knowledge, we can now explain that a constructor is a special method which is called whenever a new object is created.

The intended purpose of the constructor is that it sets up all the internal data of the object, but you can do whatever you want with it.

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