Map = function () {
this.objects = new Object();
// 加入元素
this.put = function (key, value) {
this.objects[key] = value;
};
// 删除元素
this.remove = function (key) {
this.objects[key] = undefined;
};
// 是否存在某键值
this.containsKey = function (key) {
return this.objects[key] ? true : false;
};
// 获取某元素
this.get = function(key) {
return this.objects[key];
};
// 是否存在某值
this.containsValue = function (value) {
for (var temp in this.objects) {
if (this.objects[temp] == value) {
return true;
}
}
return false;
};
// 集合大小
this.size = function () {
var counter = 0;
for (var temp in this.objects) {
counter ++;
}
return counter;
}
}
原文:http://www.cnblogs.com/echo-ling/p/7478582.html