Constructor Function

Also known as Object Constructor Function.
In ES 2009 classes had to be defined using functions.
This function (known as a constructor function) will create a new class called MyClass.

function MyClass() { 

While most object orientated languages use a class-based inheritance model, JavaScript doesn't.
JavaScript classes are based on a prototype inheritance model.
This means that all JavaScript objects have a property called "prototype" which points to its corresponding "object prototype" object.
It is this "object prototype" that inherits the properties and methods.

You can create objects of this type by calling the constructor function with the new keyword.

var myObject1 = new MyClass(); 
var myObject2 = new MyClass();

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext