A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Class_ctor_no_new below:

TypeError: class constructors must be invoked with 'new' - JavaScript

TypeError: class constructors must be invoked with 'new'

The JavaScript exception "class constructors must be invoked with 'new'" occurs when a class constructor is called without the new keyword. All class constructors must be called with new.

Message
TypeError: Class constructor X cannot be invoked without 'new' (V8-based)
TypeError: Class constructors cannot be invoked without 'new' (V8-based)
TypeError: class constructors must be invoked with 'new' (Firefox)
TypeError: Cannot call a class constructor without |new| (Safari)
Error type What went wrong?

In JavaScript, calling a function without new and constructing a function with new are two distinct operations, and functions can behave differently depending on how they are called.

Traditionally, JavaScript functions have been used as both constructors and normal functions, and can detect how they were called using new.target. However, class constructors are always constructors and cannot be called as normal functions.

Examples Invalid cases
class X {}

X(); // TypeError: class constructors must be invoked with 'new'
Valid cases See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4