用js写了一个Map,带遍历功能,请大家点评下啦。
//map.js
Array.prototype.remove = function(s) {
for (var i = 0; i < this.length; i++) {
if (s == this[i])
this.splice(i, 1);
}
}
function Map() {
this.keys = new Array();
this.data = new Object();
this.put = function(key, value) {
if(this.data[key] == null){
this.keys.push(key);
}
this.data[key] = value;
};
this.get = function(key) {
return this.data[key];
};
this.remove = function(key) {
this.keys.remove(key);
this.data[key] = null;
};
this.each = function(fn){
if(typeof fn != 'function'){
return;
}
var len = this.keys.length;
for(var i=0;i
Test Map


