var Hash = function(obj) { obj = obj || {}; for (var key in obj) { this[key] = obj[key]; } return this; }; Hash.prototype = { author: "zxx", each: function(fn) { for (var key in this) { this.has(key) && fn(this[key], key, this); } return this; }, has: function(key) { return this.hasOwnProperty(key); }, keyOf: function(value) { var keyof = false; for (var key in this) { if (keyof === false && this.has(key) && this[key] === value) { keyof = key; } } return keyof; }, hasValue: function(value) { return !!this.keyOf(value); }, extend: function(obj) { obj = obj || {}; for (var key in obj) { if (obj.hasOwnProperty(key)) { this.set(key, obj[key]); } } return this; }, combine: function(obj) { obj = obj || {}; for (var key in obj) { if (obj.hasOwnProperty(key)) { this.include(key, obj[key]); } } return this; }, erase: function(key) { if (this.has(key)) { delete this[key]; } return this; }, map: function(fn) { var objMap = {}; typeof fn == "function" && this.each(function(value, key) { objMap[key] = fn(value); }); return new Hash(objMap); }, filter: function(fn) { var objFilter = {}; typeof fn == "function" && this.each(function(value, key) { if (fn(value, key) == true) { objFilter[key] = value; } }); return new Hash(objFilter); }, every: function(fn) { var isEveryPass = true; typeof fn == "function" && this.each(function(value, key) { if (isEveryPass == true && fn(value, key) == false) { isEveryPass = false; } }); return isEveryPass; }, some: function(fn) { var isSomePass = false; typeof fn == "function" && this.each(function(value, key) { if (isSomePass == false && fn(value, key) == true) { isSomePass = true; } }); return isSomePass; }, get: function(key) { if (this.has(key)) { return this[key]; } return null; }, set: function(key, value) { if (this.has(key) || !this[key]) { this[key] = value; } return this; }, empty: function() { this.each(function(value, key, hash) { delete hash[key]; }); return this; }, include: function(key, value) { if (typeof this[key] + "" === "undefined") { this[key] = value; } return this; }, getClean: function() { var obj = {}; for (var key in this) { if (this.has(key)) { obj[key] = this[key]; } } return obj; }, getKeys: function() { var arrKeys = []; this.each(function(value, key) { arrKeys.push(key); }); return arrKeys; }, getValues: function() { var arrValues = []; this.each(function(value, key) { arrValues.push(value); }); return arrValues; }, getLength: function() { var length = 0; this.each(function() { length++; }); return length; }, toQueryString: function() { var queryString = []; this.each(function(value, key) { var queryPart; if (value instanceof Array) { var queryArr = {}; for (var from = 0; from<value.length; from++) { queryArr[from] = value[from]; } queryPart = new Hash(queryArr).toQueryString(); } else if (typeof value == "object") { queryPart = new Hash(value).toQueryString(); } else { queryPart = key + '=' + encodeURIComponent(value); } if (value !== null) { queryString.push(queryPart); } }); return queryString.join('&'); } };