Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow not using new #59

Closed
towc opened this issue Nov 23, 2019 · 0 comments
Closed

allow not using new #59

towc opened this issue Nov 23, 2019 · 0 comments

Comments

@towc
Copy link

towc commented Nov 23, 2019

I was trying to figure out why I had an obscure EventEmitter error, and it took me very long to figure out that I missed out new.

Most of the express ecosystem constructs instances without using new, which is probably why I was confused. I'm not suggesting new is completely dropped as that would break everyone else's code, but that not using new should work as well.

It should be quite straight forward to implement. For plain node, this works:

> function X() { if (this === global) return new X(); this.y = 2 }; [X(), new X()]
[ X { y: 2 }, X { y: 2 } ]

I'm not sure if this would work with bundlers.

If you don't want to allow that behaviour, it would be nice to at least throw an error saying that you didn't use new, instead of resulting in this getting thrown:

events.js:85
  if (this._events === undefined ||
           ^

TypeError: Cannot read property '_events' of undefined
    at EventEmitter.init (events.js:85:12)
    at EventEmitter (events.js:44:21)
    at Store (/app/node_modules/express-session/session/store.js:33:16)
    at KnexStore (/app/node_modules/connect-session-knex/index.js:190:9)
    at Object.<anonymous> (/app/src/app.js:20:24)
    ...
@gx0r gx0r closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants