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

"constructor" property of function prototype objects does not show up in autocomplete suggestions #15199

Closed
todor2810 opened this issue Sep 5, 2017 · 4 comments
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed. util Issues and PRs related to the built-in util module.

Comments

@todor2810
Copy link

todor2810 commented Sep 5, 2017

Example:

> function f() {}
> f.prototype.
f.prototype.__defineGetter__      f.prototype.__defineSetter__      f.prototype.__lookupGetter__
f.prototype.__lookupSetter__      f.prototype.__proto__             f.prototype.constructor
f.prototype.hasOwnProperty        f.prototype.isPrototypeOf         f.prototype.propertyIsEnumerable
f.prototype.toLocaleString        f.prototype.toString              f.prototype.valueOf

> Object.getOwnPropertyNames(f.prototype);
[ 'constructor' ]

In the example above it only shows the inherited "constructor" property from Object.prototype.

Non-enumerable properties of other objects show up, though.
Example:

> let o = {};
> Object.defineProperty(o, "firstName", {value: "ted"});
> o.
o.__defineGetter__      o.__defineSetter__      o.__lookupGetter__      o.__lookupSetter__
o.__proto__             o.constructor           o.hasOwnProperty        o.isPrototypeOf
o.propertyIsEnumerable  o.toLocaleString        o.toString              o.valueOf

o.firstName
@TimothyGu
Copy link
Member

The constructor property you are seeing is an own property of f.prototype that points to f itself.

@targos
Copy link
Member

targos commented Sep 5, 2017

This is a more general issue. Take this example:

var x = Object.create(null);
x.a = 1;
x.b = 2;
var y = Object.create(x);
y.a = 3;
y.c = 4;

Completion for y.<tab><tab>:

> y.
y.a  y.b  

y.c  

I would also expect y.a to be next to y.c because the own property shadows the property on the prototype.

@todor2810
Copy link
Author

@targos Should I close the issue then?

@targos
Copy link
Member

targos commented Sep 5, 2017

@pretodor Not at all. I think it's a valid issue.

@mscdex mscdex added the util Issues and PRs related to the built-in util module. label Sep 5, 2017
@apapirovski apapirovski added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Apr 13, 2018
rubys added a commit to rubys/node that referenced this issue Jun 29, 2018
Previously, the code displayed properties backwards (e.g., showing prototype
properties before own properties).  It also did uniqueness checks during this
processing, so these checks were done backwards.

After this change, the properties continue to be displayed backwards, but
the uniqueness checks are done in the proper order.

Fixes: nodejs#15199

See also: nodejs#21586 which was discovered
during the testing of this fix.
targos pushed a commit that referenced this issue Jul 14, 2018
Previously, the code displayed properties backwards (e.g., showing
prototype properties before own properties).  It also did uniqueness
checks during this processing, so these checks were done backwards.

After this change, the properties continue to be displayed backwards,
but the uniqueness checks are done in the proper order.

See also: #21586 which was
discovered during the testing of this fix.

Fixes: #15199
PR-URL: #21588
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants