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

Any reason why Express uses setPrototypeOf? #4368

Closed
schamberg97 opened this issue Jul 29, 2020 · 3 comments
Closed

Any reason why Express uses setPrototypeOf? #4368

schamberg97 opened this issue Jul 29, 2020 · 3 comments
Labels

Comments

@schamberg97
Copy link

@schamberg97 schamberg97 commented Jul 29, 2020

Hey there! I was researching Express.JS source code and found that the init middleware (/lib/middleware/init.js) uses setPrototypeOf. However, changing object prototype is inherently slow, as stated on MDN. My question is thus the following, could Object.assign be used instead, as it is supposed to be much faster (40-50%)?

Sorry if it is a stupid question, I might not know a lot of things.

@dougwilson
Copy link
Member

@dougwilson dougwilson commented Jul 29, 2020

It is to support the sub app feature, as each express app has what it's prototype of request/response is going to be (the app.request and app.response properties) and when a request/response enters into a sub app, the app is expecting those properties and methods to exist. This helps a lot if you are mounting both express 4 and 3 apps together (same with express 5 and 4) as they have different methods and properties between each other. Object.assign does not actually work for this.

@dougwilson dougwilson added the question label Jul 29, 2020
@expressjs expressjs deleted a comment Aug 10, 2020
@anlexN
Copy link

@anlexN anlexN commented Aug 22, 2020

@dougwilson backward compatibility you say is not necessary. setProtypeOf is not modern syntax, it slow down ecmascript modernization. please give up it.
@schamberg97 can we together rewrite express with es2015+ modern syntax? 😄

@dougwilson
Copy link
Member

@dougwilson dougwilson commented Aug 22, 2020

I'm going to close it as it seems the discussion is not constructive. The compatibility I am talking about has nothing to do with Javascript, but using multiple versions of Express in the same large app.

Object.setPrototypeOf is modern and was introduced in ECMAScript 2015.

@dougwilson dougwilson closed this Aug 22, 2020
@expressjs expressjs locked and limited conversation to collaborators Aug 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.