-
Notifications
You must be signed in to change notification settings - Fork 9
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
Inner types in prototype style #41
Comments
Right because you must differ the generation of the inner class until after the constructor is done... interesting problem. |
After playing around with some JavaScript code I think it should be possible to move the inner types out of the class body. I'll need to refactor the generated code a bit first. |
Inner types in prototype style are now added to the prototype instead of being defined in the class body. All the tests still pass, and correct code is generated for the example given above. As a nice side effect the prototype style code is now more readable because the members are grouped properly. But there are probably some cases that still don't work, for both prototype style and capture style, in particular if inner and outer types have identical names. |
Ok, this seems to work pretty well now. The problems with identical names of inner and outer types are not directly related to this, so I'll open a separate issue for that. |
Inner types are currently only partly functional in prototype style. For instance, this doesn't work:
In the generated JS code
test
can't accessOuter.Inner()
properly because it is defined insideOuter
and is not exported. That could be fixed of course. But perhaps the real problem is that we mix prototype style and capture style here: while methods are defined separately and added to the prototype, inner types are defined inside the body of the outer type, creating a closure. It seems that this mixing of concepts is not completely trouble-free.It would be more consistent, and probably work out better in the long term, to define inner types in the same way as other class members in prototype style. It would also definitely be more efficient because currently inner types are completely initialized every time an instance of the outer class is created.
Implementing this is definitely not uncomplicated either though.
The text was updated successfully, but these errors were encountered: