4 ms·
The proposal[1] explains several cases where try…finally is verbose or even can result in subtle errors. The upshot for me is that this feature adds RAII to Jav
by robby_w_g 3y ago
The proposal[1] explains several cases where try…finally is verbose or even can result in subtle errors. The upshot for me is that this feature adds RAII to JavaScript. It makes resource management convenient and more maintainable. Seems like a no brainer to me.
[1] https://github.com/tc39/proposal-explicit-resource-management#definitions https://github.com/tc39/proposal-explicit-resource-managemen...
- DougBTX 3y ago> The upshot for me is that this feature adds RAII to JavaScript That doesn’t appear to be the case, a resource can be returned, but this is block scoped. It appears to be closer to a using statement in C#.
- TJSomething 3y agoBased on my reading of the spec, you can't actually return a resource, since the disposal semantics need to map exactly to calling [Symbol.dispose] in a finally block at the end of the current block. Also, unlike C#, you can have multiple using statements in the same block, which will be disposed of in LIFO order.
- monkpit 3y agoYou can create a resource without “using” it immediately, though.
- moron4hire 3y agoYou can have multiple using statements over the same block in C#.