1 //封装http请求键值对的函数 2 function Map() { 3 this.keys = new Array(); 4 this.data = {}; 5 //添加键值对 6 this.put = function(key, value) { 7 if (this.data[key] == null) { //如键不存在则给键域数组添加键名 8 this.keys.push(key); 9 } 10 this.data[key] = value; //给键索引对应的值域赋值 11 }; 12 //获取键对应的值 13 this.get = function(key) { 14 return this.data[key]; 15 }; 16 //去除键值,(去除键数据中的键名及对应的值) 17 this.remove = function(key) { 18 this.keys.remove(key); 19 this.data[key] = null; 20 }; 21 //判断键值元素是否为空 22 this.isEmpty = function() { 23 return this.keys.length == 0; 24 }; 25 //获取键值元素大小 26 this.size = function() { 27 return this.keys.length; 28 }; 29 }