Constructor Function in 1 Minute.

Austin Beaufort
2 min readMar 25, 2020

--

Online playground to type the examples: https://repl.it/languages/javascript

Once upon a time there were classes in JavaScript.

new instance of empty class produces empty object.

They CAN (they don’t have to) have these fancy things called constructor functions.

class with empty constructor function.

What’s it do?

Really only one thing. It runs every time a new ‘Book’ is made/instantiated.

That’s it. That’s the lesson.

Check out the three examples below, and have a great day!

constructor called twice because 2 unique books were made/instantiated from the class Book.
passing a variable to the constructor function that is called on each new Book instantiation.

Find me on Twitter: https://twitter.com/BeaufortAustin

--

--

Austin Beaufort
Austin Beaufort

No responses yet