minor
This commit is contained in:
parent
2035e46305
commit
4dc42722c9
1 changed files with 4 additions and 2 deletions
|
@ -83,7 +83,7 @@ let user = new function() {
|
|||
The constructor can't be called again, because it is not saved anywhere, just created and called. So this trick aims to encapsulate the code that constructs the single object, without future reuse.
|
||||
````
|
||||
|
||||
## Dual-syntax constructors: new.target
|
||||
## Constructor mode test: new.target
|
||||
|
||||
```smart header="Advanced stuff"
|
||||
The syntax from this section is rarely used, skip it unless you want to know everything.
|
||||
|
@ -109,7 +109,9 @@ new User(); // function User { ... }
|
|||
*/!*
|
||||
```
|
||||
|
||||
That can be used to allow both `new` and regular calls to work the same. That is, create the same object:
|
||||
That can be used inside the function to know whether it was called with `new`, "in constructor mode", or without it, "in regular mode".
|
||||
|
||||
We can also make both `new` and regular calls to do the same, like this:
|
||||
|
||||
```js run
|
||||
function User(name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue