6 description: Object generic methods
8 license: MIT-style license.
12 provides: [Object, Hash]
20 subset: function(object, keys){
22 for (var i = 0, l = keys.length; i < l; i++){
24 results[k] = object[k];
29 map: function(object, fn, bind){
31 for (var key in object){
32 if (object.hasOwnProperty(key)) results[key] = fn.call(bind, object[key], key, object);
37 filter: function(object, fn, bind){
39 Object.each(object, function(value, key){
40 if (fn.call(bind, value, key, object)) results[key] = value;
45 every: function(object, fn, bind){
46 for (var key in object){
47 if (object.hasOwnProperty(key) && !fn.call(bind, object[key], key)) return false;
52 some: function(object, fn, bind){
53 for (var key in object){
54 if (object.hasOwnProperty(key) && fn.call(bind, object[key], key)) return true;
59 keys: function(object){
61 for (var key in object){
62 if (object.hasOwnProperty(key)) keys.push(key);
67 values: function(object){
69 for (var key in object){
70 if (object.hasOwnProperty(key)) values.push(object[key]);
75 getLength: function(object){
76 return Object.keys(object).length;
79 keyOf: function(object, value){
80 for (var key in object){
81 if (object.hasOwnProperty(key) && object[key] === value) return key;
86 contains: function(object, value){
87 return Object.keyOf(object, value) != null;
90 toQueryString: function(object, base){
93 Object.each(object, function(value, key){
94 if (base) key = base + '[' + key + ']';
96 switch (typeOf(value)){
97 case 'object': result = Object.toQueryString(value, key); break;
100 value.each(function(val, i){
103 result = Object.toQueryString(qs, key);
105 default: result = key + '=' + encodeURIComponent(value);
107 if (value != undefined) queryString.push(result);
110 return queryString.join('&');
120 has: Object.prototype.hasOwnProperty,
122 keyOf: function(value){
123 return Object.keyOf(this, value);
126 hasValue: function(value){
127 return Object.contains(this, value);
130 extend: function(properties){
131 Hash.each(properties || {}, function(value, key){
132 Hash.set(this, key, value);
137 combine: function(properties){
138 Hash.each(properties || {}, function(value, key){
139 Hash.include(this, key, value);
144 erase: function(key){
145 if (this.hasOwnProperty(key)) delete this[key];
150 return (this.hasOwnProperty(key)) ? this[key] : null;
153 set: function(key, value){
154 if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
159 Hash.each(this, function(value, key){
165 include: function(key, value){
166 if (this[key] == undefined) this[key] = value;
170 map: function(fn, bind){
171 return new Hash(Object.map(this, fn, bind));
174 filter: function(fn, bind){
175 return new Hash(Object.filter(this, fn, bind));
178 every: function(fn, bind){
179 return Object.every(this, fn, bind);
182 some: function(fn, bind){
183 return Object.some(this, fn, bind);
187 return Object.keys(this);
190 getValues: function(){
191 return Object.values(this);
194 toQueryString: function(base){
195 return Object.toQueryString(this, base);
200 Hash.extend = Object.append;
202 Hash.alias({indexOf: 'keyOf', contains: 'hasValue'});