Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Enforcing the usage of new #26

Open
AlexisTM opened this issue Nov 22, 2018 · 0 comments
Open

Enforcing the usage of new #26

AlexisTM opened this issue Nov 22, 2018 · 0 comments

Comments

@AlexisTM
Copy link

As the new keyword is mandatory, the usage should be enforced.

The current stage is that the event dispatch fails if you forget the new but it is not clear why. Adding a check that new has been used can give a meaningful error instead.

The shortest way seems to be the following:

if (!(this instanceof RobustWebSocket))
    throw new Error('Constructor called without new');
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant