javascript 实现java中的Map (高效)[转]
    javascript实现java中的Map,代码是在国外的一个网站上看到的(http://stackoverflow.com/questions/368280/javascript-hashmap-equivalent
),自己稍作了修改,之前也看到过有人用2个数组实现了Map,但是我感觉效率比较低,现在这个我感觉效率还可以,自己做了下测试,代码如下: 
Map.js
- 
function?Map(linkItems)?{? ??
 
- 
????
this
.current?=?undefined;? 
??
 
- 
????
this
._size?=?
0
;? ??
 
- 
????
if
(linkItems?===?
false
){ ??
 
- 
????????
this
.disableLinking();? ??
 
- 
????}? ??
 
- 
} ??
 
- 
?
 
- 
?
 
- 
?
 
- 
??
 
- 
Map.noop?=?function()?{? ??
 
- 
????
return
?
this
;? ??
 
- 
};? ??
 
- 
?
 
- 
?
 
- 
?
 
- 
??
 
- 
Map.illegal?=?function()?{? ??
 
- 
????
throw
?
new
?Error(
"非法操作,Map已经被禁用"
);? ??
 
- 
};? ??
 
- 
?
 
- 
?
 
- 
?
 
- 
?
 
- 
?
 
- 
??
 
- 
Map.from?=?function(obj,?foreignKeys)?{? ??
 
- 
????var?map?=?
new
?Map;? 
??
 
- 
????
for
(var?prop?in?obj)?{? 
??
 
- 
????????
if
(foreignKeys?||?obj.hasOwnProperty(prop)){ 
??
 
- 
????????????map.put(prop,?obj[prop]);? ??
 
- 
????????}? ??
 
- 
????}? ??
 
- 
????
return
?map;? 
??
 
- 
};? ??
 
- 
?
 
- 
?
 
- 
?
 
- 
??
 
- 
Map.prototype.disableLinking?=?function()?{? ??
 
- 
????
this
.link?=?Map.noop;? 
??
 
- 
????
this
.unlink?=?Map.noop;? 
??
 
- 
????
this
.disableLinking?=?Map.noop;? 
??
 
- 
????
this
.next?=?Map.illegal;? 
??
 
- 
????
this
.key?=?Map.illegal;? 
??
 
- 
????
this
.value?=?Map.ille