js自定义字典对象,键值对

//自定义字典对象
function Dictionary(){
	this.data = new Array();
 
	this.put = function(key,value){
		this.data[key] = value;
	};
	this.get = function(key){
		return this.data[key];
	};
	this.remove = function(key){
		this.data[key] = null;
	};
	this.isEmpty = function(){
		return this.data.length == 0;
	};
	this.size = function(){
		return this.data.length;
	};
}

//自定义Map对象
function Map(){
	this.keys = new Array();
	this.data = new Array();
 
	this.put = function(key,value){
		if(this.data[key] == null){
			this.keys.push(value);
		}
		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.isEmpty = function(){
		return this.keys.length == 0;
	};
 
	this.size = function(){
		return this.keys.length;
	};
}

你可能感兴趣的:(Web)