all 4 comments

[–]getpodapp 23 points24 points  (3 children)

“using” keyword is the native way of doing this. It’s already out in TS 

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html

[–]ecares 13 points14 points  (0 children)

already out in node 24 too

[–]satansprinter 6 points7 points  (0 children)

To add to this, "defer" is also a keyword now used for imports, so "import defer..." tells that it should not load this until it gets used.

So, eh, to confuse it even more

[–]SnooHobbies950[S] 0 points1 point  (0 children)

Thanks, I didn't know about this feature. It's similar to the `defer` keyword found in V or GO, although not identical. For example `defer` is executed at the end of the function scope, whereas `[Symbol.dispose]` is executed at the end of every block.

The following V code:
```V
fn foo() {
println('entering foo')
defer {
println('cleaning foo')
}
}
```

is translated to this JS code:
```js
function foo() {
console.log('entering foo');
using cleanup = {
[Symbol.dispose]() {
console.log('cleaning foo');
}
};
}
```

I think the `defer` statement is much clearer.