7 ms·
JS has the using keyword for this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using https://developer.mozilla.org/en-US/docs/W
by mcintyre1994 2mo ago
JS has the using keyword for this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- kaashif 2mo agoWhat if you forget to use that and just use let or const? It is better than plain try-finally or defer because you don't have to remember how to dispose of the resources but in terms of remember to dispose of the resource at all, I don't think that is all that different from Python's with or Java's try-with-resources. You can just forget to use using, with, try-with-resources. There isn't any way to forget to drop a resource if you have RAII.
- throw-the-towel 2mo agoYes, but you also have this problem with `defer`.
- masklinn 2mo agoAnd try/finally.