Skip to content
Advertisement

Javascript “Not a Constructor” Exception while creating objects

I am defining an object like this:

JavaScript

I then try to create an instance like this:

JavaScript

but this exception is thrown:

JavaScript

What could be wrong? I googled around a lot, but I still can’t figure out what I am doing wrong.

Advertisement

Answer

The code as posted in the question cannot generate that error, because Project is not a user-defined function / valid constructor.

JavaScript

You’ve probably done something like this:

JavaScript

Variable declarations using var are hoisted and thus always evaluated before the rest of the code. So, this can also be causing issues:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement