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

Can class.initialize be called more than once? #1

Open
ljharb opened this Issue Jan 6, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@ljharb
Copy link

ljharb commented Jan 6, 2019

No description provided.

@littledan

This comment has been minimized.

Copy link
Owner

littledan commented Jan 6, 2019

Hmm, I wasn't thinking of making limitations on this. Do you think there should be? What sorts of guarantees would that lead to? (A constructor can recurse anyway...)

@ljharb

This comment has been minimized.

Copy link

ljharb commented Jan 7, 2019

Can you elaborate on a constructor recursing? Circular prototype chains are forbidden and the super return trick would only work on one object, no?

@littledan

This comment has been minimized.

Copy link
Owner

littledan commented Jan 7, 2019

I don't mean any of that, it's just that if we made such a restriction, it would be possible for the constructor to make further calls to new, and use that to class.instantiate many objects, the same as if we don't have the restriction.

@ljharb

This comment has been minimized.

Copy link

ljharb commented Jan 7, 2019

oh sure, i ts not like restricting this to one call prevents multiple calls - a dev can always construct classes in a loop and instantiate multiple objects. It’s more like, super() can only be called once, so what’s the use case for calling this more than once? How likely is it that calling it more than once is a bug, versus being intentional? If the intentional use case is rare enough, and still possible just with more boilerplate, and the buggy case is more common, then it seems beneficial to ensure it’s only called once (also, that you can’t both call it, and super(), on the same instance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment