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

Rework to using classes instead of prototypes #318

Open
43081j opened this issue Apr 25, 2024 · 0 comments
Open

Rework to using classes instead of prototypes #318

43081j opened this issue Apr 25, 2024 · 0 comments
Labels
5.x Next major of the library

Comments

@43081j
Copy link
Contributor

43081j commented Apr 25, 2024

In much of this library, we use functions as constructors and add methods to the prototype, using util.inherits for inheritance

We should probably rework this to use classes now that they're widely available.

For example:

chai-http/lib/request.js

Lines 307 to 318 in cc58a4b

function TestAgent(app) {
if (!(this instanceof TestAgent)) return new TestAgent(app);
if (typeof app === 'function') app = http.createServer(app);
(Agent || Request).call(this);
this.app = app;
if (typeof app !== 'string' && app && app.listen && app.address && !app.address()) {
this.app = app.listen(0)
}
}
util.inherits(TestAgent, Agent || Request);
TestAgent.prototype.close = function close(callback) {

Could be:

class TestAgent extends (Agent || Request) {
  constructor(app) {
    super();
    if (typeof app === 'function') app = http.createServer(app);
    this.app = app;
    if (typeof app !== 'string' && app && app.listen && app.address && !app.address()) {
      this.app = app.listen(0)
    }
  }

  close(callback) {
    // ...
  }
}
@43081j 43081j added the 5.x Next major of the library label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.x Next major of the library
Projects
None yet
Development

No branches or pull requests

1 participant