-
Notifications
You must be signed in to change notification settings - Fork 3
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
Comments
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...) |
Can you elaborate on a constructor recursing? Circular prototype chains are forbidden and the super return trick would only work on one object, no? |
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. |
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) |
Note that if any fields are private, |
That’s good to know; i was also thinking of preventing it from being called on two different objects. |
I'm not sure what sort of invariants it would provide to prevent |
No description provided.
The text was updated successfully, but these errors were encountered: