A way to fire logic at the end of completion of the current class method (regardless of super call order).

Isiah Meadows isiahmeadows at gmail.com
Sat Feb 9 22:11:47 UTC 2019


I get that, but it's usually part of the API subclassing contract that
the superclass *explicitly* depends on certain parts of the subclass.
Abstract classes immediately come to mind, and I'd say it's no more
leaking than any inherited method. It's not giving them any more
access to information than they would've gotten from an explicit `if
(new.target === Subclass) this.init()` call at the end (which is
basically what I want mod the exposed method).

-----

Isiah Meadows
contact at isiahmeadows.com
www.isiahmeadows.com

On Sat, Feb 9, 2019 at 4:53 PM Jordan Harband <ljharb at gmail.com> wrote:
>
> If the superclass constructor has a way to run any code after subclass constructors, then implementation details of the *subclasses* are then leaked.
>
> On Sat, Feb 9, 2019 at 2:15 AM Isiah Meadows <isiahmeadows at gmail.com> wrote:
>>
>> I've also had *several* scenarios where I could've used this
>> personally. I feel ES classes are overly restrictive in preventing
>> this, since it basically forces you to force subclasses to do
>> something like `this.init()` right after the class is allocated,
>> leaking implementation details left and right.
>>
>> -----
>>
>> Isiah Meadows
>> contact at isiahmeadows.com
>> www.isiahmeadows.com
>>
>> On Fri, Feb 8, 2019 at 1:22 AM #!/JoePea <joe at trusktr.io> wrote:
>> >
>> > I many times find myself in cases where a base class wants to ensure that logic is always fired after the current method's execution, so that for example no matter in which order sub classes call the `super` method, the `super` method can still guarantee that logic fires after the whole stack of the same method in the class hierarchy.
>> >
>> > So what I can do now is use `Promise.resolve().then(() => { ... })` to schedule that logic for later, that way all the invocations of a `foo` method along the class hierarchy have all fired. But this means that other code can also fire before the next microtask.
>> >
>> > Is there some way to do it? If not, I wonder if some language feature for doing it would be possible?
>> >
>> > - Joe
>> > _______________________________________________
>> > es-discuss mailing list
>> > es-discuss at mozilla.org
>> > https://mail.mozilla.org/listinfo/es-discuss
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list