-
-
Save 1moita/e68de10bfcdd30474ae735af8b603635 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