Last active
August 29, 2015 14:23
-
-
Save liushuping/80ed29243e3c2f815ed6 to your computer and use it in GitHub Desktop.
A map implementation in JavaScript
This file contains hidden or 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
/* | |
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