Proposal: Syntax sugar for single exit and early exit functions.
Christian Mayer
mail at ChristianMayer.de
Wed Nov 19 14:16:19 PST 2014
Am 18.11.2014 um 22:03 schrieb Brendan Eich:
> Christian Mayer wrote:
>> What I actually sometimes really miss in JavaScript (having a big C++
>> background) are destructors.
>>
>> (I haven't checked if they are in any new version proposal, though)
>
> No, as JS has no stack storage class, only we-hope-unobservable GC, no
> destructors.
I fully understand that something called at GC time won't work - but
that's not a real destructor for me, that would be a sort of
"destroyer"... :)
The destructor should IMHO be called when the JS internal ref count gets
to 0, i.e. when the object gets released to the GC to do it's job when
it wants to.
(This could actually be generalized by offering a callback function that
gets called every time the internal refcount gets decreased... The
current ref count could be passed as a parameter then)
One very obvious use case for me would be debugging and making sure that
my objects aren't leaking. But anything could make sense where
destructors are usually used for.
More information about the es-discuss
mailing list