Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Iterator.prototype.constructor #60

Closed
zloirock opened this issue Oct 25, 2019 · 10 comments
Closed

Iterator.prototype.constructor #60

zloirock opened this issue Oct 25, 2019 · 10 comments

Comments

@zloirock
Copy link
Contributor

Now it's Object, maybe it should be Iterator?

@zloirock
Copy link
Contributor Author

Theoretically, it could be a breaking change since could affect some old code:

[].values().constructor; // => Object

but unlikely that someone used it.

@michaelficarra
Copy link
Member

Can you give some examples of why it would be useful to do this?

@ljharb
Copy link
Member

ljharb commented Oct 25, 2019

Because [].values() instanceof Iterator should be true.

@zloirock
Copy link
Contributor Author

JS objects contain .constructor and if it's already a part of the objects model, we should not forget about. Someone uses it for identification of objects, someone for subclassing. I'm not a fan of active usage of this property, but since some libraries and developers use it...

@michaelficarra
Copy link
Member

@ljharb Iterator[@@hasInstance]?

@devsnek
Copy link
Member

devsnek commented Oct 25, 2019

OrdinaryHasInstance of o and C uses C.prototype, not o.constructor. That being said, I don't really see any reason not to update the constructor property. I seriously doubt it would break anyone.

@michaelficarra
Copy link
Member

Okay so is there any tangible benefit to making this change? Is it just for consistency?

@zloirock
Copy link
Contributor Author

@michaelficarra since we must respect the concepts that are already used in the language?

@ljharb
Copy link
Member

ljharb commented Oct 25, 2019

Consistency is a tangible benefit.

(yes, Symbol.hasInstance would help, but why when we could fix the prototype and the constructor)

@zloirock
Copy link
Contributor Author

zloirock commented Oct 25, 2019

@ljharb @@hasInstance is not required, the prototype already added and your example already works with this proposal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants