Coder Social home page Coder Social logo

Comments (5)

hueniverse avatar hueniverse commented on June 14, 2024

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.

harrytruong avatar harrytruong commented on June 14, 2024

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.

harrytruong avatar harrytruong commented on June 14, 2024

[deleted] Commented on wrong issue ticket.

from hapi-contrib.

hueniverse avatar hueniverse commented on June 14, 2024

What's your use case here?

from hapi-contrib.

harrytruong avatar harrytruong commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.