Constructor Function

Also called an Object Constructor Function.
Putting "new" in front of a function call turns that function into a constructor call.
This means it does 4 additional things:
*) a brand new empty object is created
*) the object is linked to something ( see later )
*) the function gets bound as the "this" keyword for the purposes of the function call
*) if the function does not return anything, then it will implicitly return "this"

Returns 'this' if the function does not return its own object.

function Person ( first, last ) { 
   this.firstName = first;
   this.lastName = last;
var myDad = new Person ("David", "Smith");

new Function (arg1, arg2, [ ... ], bodyString)

var myDad = { 
   init : function (first, last) {
      this.firstName = first;
      this.lastName = last;

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