Symbol
A built-in object that serves as a namespace for globally-unique identifiers.
Compiles to a regular JavaScript Symbol.
t
type tType representing a Symbol.
make
let make: string => tmake(key)
Makes a new unique Symbol value.
Examples
RESCRIPTSymbol.make("sym1")->Symbol.description == Some("sym1")
getFor
let getFor: string => option<t>getFor(key)
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. Otherwise a new Symbol gets created and registered with key.
Examples
RESCRIPTSymbol.getFor("sym1") == Symbol.getFor("sym1")
keyFor
let keyFor: t => option<string>keyFor(key)
Retrieves a shared Symbol key from the global Symbol registry for the given Symbol.
Examples
RESCRIPTlet globalSym = Symbol.getFor("sym1") // Global symbol
globalSym->Option.flatMap(Symbol.description) == Some("sym1")
description
let description: t => option<string>description
Returns Some(string) containing the description of this symbol, or None if the symbol has no description.
Examples
RESCRIPTlet sym = Symbol.make("sym1")
Symbol.description(sym) == Some("sym1")
toString
let toString: t => stringtoString
// Returns a string representing this symbol value.
Examples
RESCRIPTlet sym = Symbol.make("sym1")
Symbol.toString(sym) == "Symbol(sym1)"
asyncIterator
let asyncIterator: tasyncIterator is the well-known symbol used by asynchronous iterables.
See Symbol.asyncIterator on MDN.
hasInstance
let hasInstance: thasInstance is used by custom instanceof checks.
See Symbol.hasInstance on MDN.
isConcatSpreadable
let isConcatSpreadable: tisConcatSpreadable controls whether objects are flattened when passed to Array.concat.
See Symbol.isConcatSpreadable on MDN.
iterator
let iterator: titerator is returned by objects that can be iterated with for..of.
See Symbol.iterator on MDN.
match
let match: tmatch customises how values respond to String.prototype.match.
See Symbol.match on MDN.
matchAll
let matchAll: tmatchAll customises how values respond to String.prototype.matchAll.
See Symbol.matchAll on MDN.
replace
let replace: treplace customises how values respond to String.prototype.replace.
See Symbol.replace on MDN.
search
let search: tsearch customises how values respond to String.prototype.search.
See Symbol.search on MDN.
species
let species: tspecies lets constructors return a different derived constructor when methods create new instances.
See Symbol.species on MDN.
split
let split: tsplit customises how values respond to String.prototype.split.
See Symbol.split on MDN.
toPrimitive
let toPrimitive: ttoPrimitive customises how objects convert to primitive values.
See Symbol.toPrimitive on MDN.
toStringTag
let toStringTag: ttoStringTag customises the default tag shown by Object.prototype.toString.
See Symbol.toStringTag on MDN.
unscopables
let unscopables: tunscopables marks properties that should be skipped by with.
See Symbol.unscopables on MDN.
ignore
let ignore: t => unitignore(symbol) ignores the provided symbol and returns unit.
This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.