14/3 Digitizing People - what's wrong with "new function()"?


#1

My code works fine if I do

var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName);
}

It fails if I do

var printPerson = new function(person) {
console.log(person.firstName + " " + person.lastName);
}

Can somebody explain, why?


#2

The keyword "new" is used to create an instance of object.
Your function printPerson is not constructor. So this syntax:

is not valid.

You can read more about this here.


#3

Thanks, Julieta! I've just come around classes and try to wrap my mind around the concept of "instance".


#4

JavaScript uses prototypes where many other object-oriented languages use classes for inheritance.
This article might be helpful to you.