Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAny reason why Express uses setPrototypeOf? #4368
Comments
|
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 backward compatibility you say is not necessary. setProtypeOf is not modern syntax, it slow down ecmascript modernization. please give up it. |
|
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. |
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.