Skip to content

QUESTION: Why is obj.__proto__=... being used instead of calling Object.create #2613

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

Closed
g00dnatur3 opened this issue Apr 3, 2015 · 4 comments

Comments

@g00dnatur3
Copy link

In the ./lib/express.js & in the ./lib/router/index.js (and probably more places) the __proto__ is being set directly either in the form obj.__proto__ = ... or in the form obj = { __proto__: ... }

Mozilla does not recommend this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto

they say it will heavily impact performance in modern javascript engines... I am not sure how relevant this is to vp8 engine, but Mozilla suggests using Object.create instead.

Is there a reason why you opted no to use Object.create?

Just very curious about this decision.

Thank you

@g00dnatur3 g00dnatur3 changed the title QUESTION: Why is __proto__ being mutated instead of calling Object.create QUESTION: Why is obj.__proto__=... being used instead of calling Object.create Apr 3, 2015
@rlidwka
Copy link
Member

rlidwka commented Apr 3, 2015

Because obj is not an object but a function. You can't possibly use Object.create there.

Also, see discussion in #2413

@dougwilson
Copy link
Contributor

__proto__ is now part of the ES6 standard. There are several other questions/discussions in this repo. Feel free to search around in here to see them. #1967 was the first I searched up for you :)

@aoberoi
Copy link

aoberoi commented Nov 22, 2015

Sorry for reviving an old issue, but I'm running node v4.2.2 and Object.setPrototypeOf() is available. I'm not sure which version it was added in, but it seems (at least the 4.x versions of) express targets 0.10.x as a minimum. Do we have any word on what version of node express v5 will target?

@dougwilson
Copy link
Contributor

There is currently an open discussion about this (you can find it by looking at the open issues), but the highest minimum we will go for 5.0 is 4.0.0. Regardless, the property is part of the ES6 spec and will likely stick around for some time. Everyone asking so far has not had any legitimate reason not to use it besides "oh, it's deprecated". That's all well and good, but as long as we support node.js versions without setPrototypeOf, we have no other choice.

@expressjs expressjs locked and limited conversation to collaborators Nov 22, 2015
@dougwilson dougwilson added the 4.x label Feb 19, 2017
neosiae pushed a commit to neosiae/express that referenced this issue Feb 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants