Skip to content

Instantly share code, notes, and snippets.

@1moita
Forked from evinism/yesindexing.js
Created October 17, 2021 22:39
Show Gist options
  • Save 1moita/e68de10bfcdd30474ae735af8b603635 to your computer and use it in GitHub Desktop.
Save 1moita/e68de10bfcdd30474ae735af8b603635 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment