Constructor function syntax

What’s the difference between the syntax in the following two examples?

a.

var Person = function(firstAndLast) {
  var fullName = firstAndLast;

  this.getFirstName = function() {
    return fullName.split(" ")[0];
  };

}

var bob = new Person("Bob Ross");
bob.getFirstName();

and b.

function Circle(radius) {
   this.radius = radius; 
   this.draw = function(){
   console.log('draw');
   }
}

const circle = new Circle(1);

I think there might be more going on here.

What are you asking then? They are two separate functions that do separate things. The main syntax difference is declaring the function

I assume you mean the syntax, and if so, for all practical purposes these are exactly the same (or would be if the two were actually comparable)

Ok, that helps me think about it more clearly. Thanks.

The difference between the two styles of declaring the object is within the closure.
“this” keyword reference to itself is not used for creating private variable, it is meant to be a self reference.

When you create the new Circle object, this keyword is pointing to both radius and object.
When Person is created, fullName is an actual block scope variable which is contained within the scope of a Person. fullName is not destroy because the reference it has to bob that contain the closure.

console.log( bob ); //Person { getFirstName: f }
console.log( circle ); //Circle { radius: 1, draw: f }

To create a closure for the Circle, do this…

function Circle( radius ) {
   this.radius = radius;
   this.draw = function( ) {
      console.log( 'draw' );
   }

   return {
      draw : this.draw
   };
}