Created
June 15, 2020 00:40
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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