Skip to content

Instantly share code, notes, and snippets.

@sebdeckers
Last active November 25, 2015 02:19
Show Gist options
  • Save sebdeckers/936dc0b371c5601b31c6 to your computer and use it in GitHub Desktop.
Save sebdeckers/936dc0b371c5601b31c6 to your computer and use it in GitHub Desktop.
Map
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