3 ms·
Meh, I don't think the more confusing interface defined in that issue warrants the added complexity. using should only be used for local variables, and the exam
by hn_throwaway_99 3y ago
Meh, I don't think the more confusing interface defined in that issue warrants the added complexity. using should only be used for local variables, and the example you give is fundamentally complicated by who should be responsible for disposing of the object:
function inner(defaultResource) {
const resource = defaultResource ?? getResource();
using resource;
}
That is, if a defaultResource is passed in, the caller should be responsible for disposing it, while if it wasn't passed in, the inner function should be responsible for disposing it.
IMO cases like this are better handled with linting rules that forbid use of using on anything but an object directly returned by a function on that line.