Skip to content

Instantly share code, notes, and snippets.

@wh1tney
Created August 20, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wh1tney/d660cb58514fc9577400 to your computer and use it in GitHub Desktop.
Save wh1tney/d660cb58514fc9577400 to your computer and use it in GitHub Desktop.
JavaScript Hates You
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