Created
August 28, 2017 13:56
-
-
Save prof3ssorSt3v3/3f98667c9be23e4ba1e2b71168007c22 to your computer and use it in GitHub Desktop.
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
// Maps vs Objects | |
// ES6 Maps are a good replacement for Objects | |
// in many circumstances but not all | |
let a = {'name': 'Sherlock'}; | |
let b = {'name': 'Watson'}; | |
let people = {}; | |
people[a] = 'Detective'; // a ['object':Object] | |
people[b] = 'Doctor'; // b ['object':Object] | |
//can't use objects as keys for other objects | |
//object keys are converted into a string | |
console.log( people[a], people[b]); | |
let characters = new Map(); | |
characters.set(a, 'Detective'); | |
characters.set(b, 'Doctor'); | |
console.log( characters.get(a), characters.get(b) ); | |
for(let [key, value] of characters){ | |
console.log(`${key} = ${value}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment