3 ms·
> If the code is > obj[Symbol.dispose]() > they are notating it as `[Symbol.dispose]()`. So `obj[Symbol.dispose]()` is the same as `[Symbol.dispose]()`? Th
by vaylian 1y ago
> 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?
- masklinn 1y ago[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