Last active
          November 25, 2015 02:19 
        
      - 
      
 - 
        
Save sebdeckers/936dc0b371c5601b31c6 to your computer and use it in GitHub Desktop.  
    Map
  
        
  
    
      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
    
  
  
    
  | class Person { | |
| constructor (name, score) { | |
| this.name = name | |
| this.score = score | |
| } | |
| } | |
| const alice_foo = new Person('Alice', 10) | |
| const alice_bar = new Person('Alice', 50) | |
| const people_object = {} | |
| people_object[alice_foo.name] = alice_foo.score | |
| people_object[alice_bar.name] = alice_bar.score | |
| console.log(people_object[alice_foo.name] === alice_bar.score) // Oops! true | |
| const people_map = new Map() | |
| people_map.set(alice_foo, alice_foo.score) | |
| people_map.set(alice_bar, alice_bar.score) | |
| console.log(people_map.get(alice_foo) === alice_foo.score) // Correct! true | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment