You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Without an in-depth understanding of the spec, a naïve developer might assume that (a) would print 1 and (b) would print 2, however this is not the case. According to the proposal, x will be Defined on the instance of obj during construction. This means that the field x on Base will override the accessor x on Sub, which seems to violate developer intuition that members on Sub should override members on Base. In fact, the only way for Sub to overridex with an accessor would be to use Object.defineProperty in the constructor of Sub to replace the field with an accessor on the instance.
I only see two solutions to solve this issue:
Split a field into two operations:
Use Define on the prototype for Base to add a property with the descriptor: { enumerable: true, configurable: true, writable: true, value: undefined }
Use Set in the constructor of Base to evaluate the initializer.
Use Set semantics for fields.
Option 1 is the most consistent with the current semantics that use Define (a field on a subclass overrides a member on the superclass), but solves the above issue.
Option 2 is consistent with the state of existing compile-to-javascript languages over the last 6 years.
I believe we may need to revisit the Set vs. Define debate of public fields in light of this scenario:
Without an in-depth understanding of the spec, a naïve developer might assume that (a) would print
1and (b) would print2, however this is not the case. According to the proposal,xwill be Defined on the instance ofobjduring construction. This means that the fieldxonBasewill override the accessorxonSub, which seems to violate developer intuition that members onSubshould override members onBase. In fact, the only way forSubto overridexwith an accessor would be to useObject.definePropertyin the constructor ofSubto replace the field with an accessor on the instance.I only see two solutions to solve this issue:
Baseto add a property with the descriptor:{ enumerable: true, configurable: true, writable: true, value: undefined }Baseto evaluate the initializer.Option 1 is the most consistent with the current semantics that use Define (a field on a subclass overrides a member on the superclass), but solves the above issue.
Option 2 is consistent with the state of existing compile-to-javascript languages over the last 6 years.