4 ms·
> It’s nothing like Python’s “with” that lets you define a scope for an object to be destructed early. You can forget to use `with` as well. Destructors in pyt
by bensecure 3y ago
> It’s nothing like Python’s “with” that lets you define a scope for an object to be destructed early.
You can forget to use `with` as well. Destructors in python are called when the reference count hits zero or during a gc pass. These new typescript destructors apply to the variable, not the object, so they run when the variable goes out of scope, regardless of what other references there might be to the same object. If you want to emulate `with` more closely, you can create a new scope for your `using` declaration, and put it at the very top of that new scope.