Created
August 20, 2014 19:57
-
-
Save wh1tney/d660cb58514fc9577400 to your computer and use it in GitHub Desktop.
JavaScript Hates You
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
var foo = new Object(); | |
var bar = new Object(); | |
var map = new Object(); | |
map[foo] = "foo"; // --> map["[Object object]"] = "foo"; | |
map[bar] = "bar"; // --> map["[Object object]"] = "bar"; | |
// NOTE: second mapping REPLACES first mapping! | |
alert(map[foo]); // --> alert(map["[Object object]"]); | |
// and since map["[Object object]"] = "bar", | |
// this will alert "bar", not "foo"!! | |
// SURPRISE! ;-) | |
// Code snippet from www.toptal.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment