Omitting parentheses after new

Parentheses can be omitted even if the constructor function has arguments:
```js
new function(test) {
    return { test }
}

// Works the same as
new (function(test) {
    return { test }
})();
```
This commit is contained in:
Samuel Braun 2022-09-25 14:59:06 +02:00 committed by GitHub
parent ff4ef57c8c
commit 1b87b89f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,7 +171,7 @@ alert( new SmallUser().name ); // John
Usually constructors don't have a `return` statement. Here we mention the special behavior with returning objects mainly for the sake of completeness.
````smart header="Omitting parentheses"
By the way, we can omit parentheses after `new`, if it has no arguments:
By the way, we can omit parentheses after `new`:
```js
let user = new User; // <-- no parentheses