Skip to content

Useing the well-known symbol 'hasInstance' and other meta-programming #2

Description

@KilianKilmister

the projects in iter-tools that i checked ship with a is<instance>(inst) static method. Utilizing a static property Symbol.hasInstanceallows an object to be checked with the instanceof-operator which is also used by TypeScript for typechecking that way. eg:

class Instatiater {
  static [Symbol.hasInstance] (inst: any): inst is Instatiater { /* ...some check */ }
}

these projects could also benefit from other well-known symbols like Symbol.toStringTag, Symbol.isConcatSpreadable or Symbol.species (MDN-page on symbols featuring the well-known symbols)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions