Comments (5)
This is done to protect users of the public API from forgetting to call new
. There are two typical ways of doing this, one is passive which is what we do (just prevent it) and active (call new
in the constructor).
This is done only in publicly exposed APIs. Internal prototypes don't have that. You should have no reason to use prototypical inheritance from hapi object API interfaces.
from hapi-contrib.
Thanks for the very quick response!
This is done to protect users of the public API from forgetting to call new. There are two typical ways of doing this, one is passive which is what we do (just prevent it) and active (call
new
in the constructor).
I agree with the passive method (just preventing it), but the check logic is what I'm surprised by: this.constructor === Constructor
instead of this instanceof Constructor
.
Just to be clear, I'm not advocating for active protection.
You should have no reason to use prototypical inheritance from hapi object API interfaces.
Haha, I agree. I'm not using hapi's objects in the intended way, but I don't think it hurts to reuse and extend hapi's objects for other projects? The current implementation prevents inheritance, while the alternative would allow for it (and would still passively protect against missing new
).
from hapi-contrib.
[deleted] Commented on wrong issue ticket.
from hapi-contrib.
What's your use case here?
from hapi-contrib.
Just repeating myself here for clarity:
I have no real reason. I was playing around with reusing Hapi's components in a side project. When I extended from Server to test something, I saw the implementation, and was just curious about the rationale behind it.
Also pinging @geek here because he added this style rule back in 2012.
Just want to be 100% sure I'm not misunderstanding the reason for this.constructor === Server
. (TBH, the fact that it explicitly says // Wrong
, makes me very paranoid.)
from hapi-contrib.
Related Issues (20)
- listing extensions for individual modules on hapijs.com HOT 8
- Links for contacts are broken
- Link in Sponsorship.md is broken HOT 1
- Usage of github topics HOT 3
- Private repositories and users HOT 6
- Style guide: getters and hapi-scope-start HOT 2
- npm org and sharing access HOT 7
- State of the core module HOT 1
- New core contributor - Gil Pedersen HOT 6
- Indentation style question HOT 12
- How to handle package-lock.json? HOT 22
- Using var.ci ? HOT 3
- Utility modules should work on all supported node versions HOT 3
- Replace .npmignore with explicit `files: [ 'lib/' ]` in package.json? HOT 3
- Add takeover rules for modules with absent lead maintainer HOT 10
- BigInt support
- Add an explanation of the current desired CHANGELOG and release workflow
- Propose renaming "new contributor" label to "good first issue" HOT 4
- Additional tags in hapijs/discuss HOT 5
- Conflict in rules for object assignment HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi-contrib.