News for hackers. Stuff that matters.
Re:JavaScript's New Superpower: Explicit Resource Management by masklinn on Monday May 19, 2025 @04:18AM (#44027567)
[Symbol.dispose] is a way of creating an entry whose key is the value of the expression Symbol.dispose in the same way obj[Symbol.dispose] is a way of accessing it.

The parens are just the method definition shorthand, so it’s a shorter way of writing

    [Symbol.dispose]: function()
Bracketing was introduced because Javascript was originally defined to use bare keys so

    foo: bar
Defines an entry with the key `”foo”`, rather than an entry whose key is the value for the variable `foo`. Thus to get the latter you use

    [foo]: bar

There are no comments on this comment yet.