Skip to content

Instantly share code, notes, and snippets.

@evan-brass
Created June 15, 2020 00:40
Show Gist options
  • Select an option

  • Save evan-brass/51f2feb6e6506d90c6ebb1f4d201c8da to your computer and use it in GitHub Desktop.

Select an option

Save evan-brass/51f2feb6e6506d90c6ebb1f4d201c8da to your computer and use it in GitHub Desktop.
A simple class for creating your own well-known symbols type traits.
export default class Trait {
constructor(description) {
this.symbol = Symbol(description);
}
[Symbol.toPrimitive]() {
return this.symbol;
}
[Symbol.hasInstance](target) {
return typeof target == 'object' && target[this.symbol] !== undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment