Sometimes, we want to fix JavaScript "Not a Constructor" Exception while creating objects.
In this article, we’ll look at how to fix JavaScript "Not a Constructor" Exception while creating objects.
How to fix JavaScript "Not a Constructor" Exception while creating objects?
To fix JavaScript "Not a Constructor" Exception while creating objects, we should create constructors with regular functions or the class syntax.
For instance, instead of writing
const F = () => {};
const f = new F();
We write
class F {}
const f = new F();
to replace the arrow function with class F
.
class
is syntactic sugar for constructor functions.
Conclusion
To fix JavaScript "Not a Constructor" Exception while creating objects, we should create constructors with regular functions or the class syntax.