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:
parent
ff4ef57c8c
commit
1b87b89f2b
1 changed files with 1 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue