Skip to content

Instantly share code, notes, and snippets.

@evinism
Created October 17, 2021 22:37
Show Gist options
  • Save evinism/b1f6499b721d521aa6bc9978dfb6853e to your computer and use it in GitHub Desktop.
Save evinism/b1f6499b721d521aa6bc9978dfb6853e to your computer and use it in GitHub Desktop.
cjsp2
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"
@1moita
Copy link

1moita commented Oct 17, 2021

Wow.

@evinism
Copy link
Author

evinism commented Oct 18, 2021

this is for an upcoming article about things you could do but shouldn't. I'm even working on a worse version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment