Skip to content

Instantly share code, notes, and snippets.

@liushuping
Last active August 29, 2015 14:23
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 liushuping/80ed29243e3c2f815ed6 to your computer and use it in GitHub Desktop.
Save liushuping/80ed29243e3c2f815ed6 to your computer and use it in GitHub Desktop.
A map implementation in JavaScript
/*
A JavaScript object notition is by nature a map, however there are limitations of it: the map is not empty,
the Object prototype properties are mapped keys which are unexpected. For below example, the "toString" is by
default a key in the map.
var x = {};
x["toString"]; // function toString()
But with the Object.create method, we can create a real empty map object. What needed is just to pass null to
the method.
*/
var map = Object.create(null);
console.log(map["toString"]); // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment