/**
* 定义一个map
* 如:var map=new s.HashMap();
* */
s.HashMap=function(){
//定义长度
var length = 0;
//创建一个对象
var obj = new Object();
/**
* 判断Map是否为空
*/
this.isEmpty = function(){
return length == 0;
};
/**
* 判断对象中是否包含给定Key
*/
this.containsKey=function(key){
return (key in obj);
};
/**
* 判断对象中是否包含给定的Value
*/
this.containsValue=function(value){
for(var key in obj){
if(obj[key] == value){
return true;
}
}
return false;
};
/**
*向map中添加数据
*/
this.put=function(key,value){
if(!this.containsKey(key)){
length++;
}
obj[key] = value;
};
/**
*向map原数据 添加数据
*/
this.putAll=function(key,value){
if(!this.containsKey(key)){
length++;
}
if(this.get(key)){
obj[key] = this.get(key)+','+value;
}else{
obj[key] = value;
}
};
/**
* 根据给定的Key获得Value
*/
this.get=function(key){
return this.containsKey(key)?obj[key]
vue js 封装 HashMap
最新推荐文章于 2024-04-05 00:37:46 发布