Created
October 17, 2021 22:37
-
-
Save evinism/b1f6499b721d521aa6bc9978dfb6853e to your computer and use it in GitHub Desktop.
cjsp2
This file contains 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
class Indexable { | |
constructor(){ | |
this._indexer = Symbol(); | |
} | |
[Symbol.toPrimitive](){ return this._indexer } | |
} | |
class Animal extends Indexable {} | |
const cat = new Animal(); | |
const dog = new Animal(); | |
const talk = { | |
[cat]: 'meow', | |
[dog]: 'woof' | |
}; | |
console.log(talk[cat]); // "meow", hooray!!! | |
console.log(talk[dog]); // "woof" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is for an upcoming article about things you could do but shouldn't. I'm even working on a worse version