Skip to content

Commit 41d8375

Browse files
author
Eran Hammer
committed
Merge pull request outmoded#44 from harrytruong/fix-enforce-new-proto-inherit
use `this instanceof Server` for enforcing new on constructor
2 parents 4f20abc + 105fb4a commit 41d8375

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

‎Style.md‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,9 @@
115115

116116
#### Enforcing new on Constructor
117117

118-
- Use this.constructor === to check if a constructor function was called with new
119-
```javascript
120-
// Right
121-
Hoek.assert(this.constructor === Server, 'Server must be instantiated using new');
118+
- Use `this instanceof` to check if a constructor function was called with new. (This allows for future prototypical inheritance.)
122119

123-
// Wrong
120+
```javascript
124121
Hoek.assert(this instanceof Server, 'Server must be instantiated using new');
125122
```
126123

0 commit comments

Comments
 (0)