Loading topic
Symbol.dispose and Symbol.asyncDispose. The using and await using declarations look up these symbols on an object to find its cleanup method. Before you can write disposable objects or declare resources, you need to know what 6 min readthis binding works for regular functions and arrow functions. It also assumes you have read the previous chapter on Symbol.dispose and Symbol.asyncDispose. Here you will turn ordinary objects into5 min readlet and const, how try/finally behaves, and how to give an object a Symbol.dispose method, which the previous chapter covered. Here the focus is the using declaration itself: what it binds, when it registers a resource, what happens on each 5 min readusing declaration binds a disposable object and that you are comfortable with block scoping, try/catch/finally, and generators. The examples run in any runtime that ships explicit resource management natively, such as Node.js 24 or later and Chrome 1346 min readusing declar6 min readusing and await using bind a resource and dispose it when the block exits, and that you can write an object with Symbol.dispose or Symbol.asyncDispose. It also assumes you are comfortable with try/catch, the falsy values in JavaScript, and the micr6 min readtry/finally, an exception thrown in finally silently replaces the exception from try, and the original error is lost. The using and `await usin5 min readlet and const, the try/finally statement, and async functions. Earlier chapters showed what using and await using do at runtime. This one covers the grammar: where the parser accepts these declarations, the forms it rejects,6 min readusing and await using declarations work in a block. That includes reverse-order disposal, how null and undefined are handled, and the general syntax rules. It also assumes you know how for...of drives an iterator, including the fact that leaving a 6 min readusing declaration works well when you know, while writing the code, exactly which resources a block needs. Real code often doesn't know that. A function might open a file only when a flag is set, open one connection per item in an array, or build several resources in a constructor that must all 5 min readawait using, the reverse disposal order, SuppressedError, and the synchronous DisposableStack API (use, adopt, defer, move). AsyncDisposableStack is the asynchronous version of that API. It holds a group of resources whose cleanup may take time, 5 min readusing, await using, and DisposableStack behave. It also assumes you are comfortable with private class fields (#field), getters, and EventTarget. Earlier chapters covered how the language consumes disposables. This one covers how to build them 5 min readusing, await using, and the disposable stacks as if every engine already ran them. Support is uneven in practice. Some runtimes ship the syntax and globals natively, some ship only parts of it, and some need a compiler and a polyfill. This chapter shows how to find o6 min read