News for hackers. Stuff that matters.
Re:JavaScript's New Superpower: Explicit Resource Management by paulddraper on Sunday May 18, 2025 @01:01AM (#44019109)
That's a notational reference to a functional.

If the code is

  obj.function()
they are notating it as `function()`.

If the code is

  obj[Symbol.dispose]()
they are notating it as `[Symbol.dispose]()`.

Symbol.dispose is a symbol key.

Re:JavaScript's New Superpower: Explicit Resource Management by vaylian on Sunday May 18, 2025 @01:25AM (#44019179)
> If the code is

> obj[Symbol.dispose]()

> they are notating it as `[Symbol.dispose]()`.

So

`obj[Symbol.dispose]()` is the same as `[Symbol.dispose]()`? That doesn't seem right, because we might also have `obj2` or `obj3`. How does JavaScript know that `[Symbol.dispose]()` refers to a specific object?

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