2 ms·
Symbols are a very safe way to introduce new "protocols" in either the language standard or for application code. This is because Symbol can never conflict with
by jitl 1y ago
Symbols are a very safe way to introduce new "protocols" in either the language standard or for application code. This is because Symbol can never conflict with existing class definitions. If we use a string name for the method, then existing code semantics change.
Here are the well-known symbols that my NodeJS 22 offers when I `Symbol.<tab>`:
Symbol.asyncDispose
Symbol.asyncIterator
Symbol.dispose
Symbol.hasInstance
Symbol.isConcatSpreadable
Symbol.iterator
Symbol.keyFor
Symbol.length
Symbol.match
Symbol.matchAll
Symbol.replace
Symbol.search
Symbol.species
Symbol.split
Symbol.toPrimitive
Symbol.toStringTag
Symbol.unscopables