Requires

Provides

Object generic methods

License:
MIT-style license.
  1. 19
  2. 20
  3. 21
  4. 22
  5. 23
  6. 24
  7. 25
  8. 26
  9. 27
  10. 28
  11. 29
  12. 30
  13. 31
  14. 32
  15. 33
  16. 34
  17. 35
  18. 36
  19. 37
  20. 38
  21. 39
  22. 40
  23. 41
  24. 42
  25. 43
  26. 44
  27. 45
  28. 46
  29. 47
  30. 48
  31. 49
  32. 50
  33. 51
  34. 52
  35. 53
  36. 54
  37. 55
  38. 56
  39. 57
  40. 58
  41. 59
  42. 60
  43. 61
  44. 62
  45. 63
  46. 64
  47. 65
  48. 66
  49. 67
  50. 68
  51. 69
  52. 70
  53. 71
  54. 72
  55. 73
  56. 74
  57. 75
  58. 76
  59. 77
  60. 78
  61. 79
  62. 80
  63. 81
  64. 82
  65. 83
  66. 84
  67. 85
  68. 86
  69. 87
  70. 88
  71. 89
  72. 90
  73. 91
  74. 92
  75. 93
  76. 94
  77. 95
  78. 96
  79. 97
  80. 98
  81. 99
  82. 100
  83. 101
  84. 102
  85. 103
  86. 104
  87. 105
  88. 106
  89. 107
  90. 108
  91. 109
  92. 110
  93. 111
  94. 112
  95. 113
  96. 114
Object.extend({ subset: function(object, keys){ var results = {}; for (var i = 0, l = keys.length; i < l; i++){ var k = keys[i]; results[k] = object[k]; } return results; }, map: function(object, fn, bind){ var results = {}; for (var key in object){ if (object.hasOwnProperty(key)) results[key] = fn.call(bind, object[key], key, object); } return results; }, filter: function(object, fn, bind){ var results = {}; Object.each(object, function(value, key){ if (fn.call(bind, value, key, object)) results[key] = value; }); return results; }, every: function(object, fn, bind){ for (var key in object){ if (object.hasOwnProperty(key) && !fn.call(bind, object[key], key)) return false; } return true; }, some: function(object, fn, bind){ for (var key in object){ if (object.hasOwnProperty(key) && fn.call(bind, object[key], key)) return true; } return false; }, keys: function(object){ var keys = []; for (var key in object){ if (object.hasOwnProperty(key)) keys.push(key); } return keys; }, values: function(object){ var values = []; for (var key in object){ if (object.hasOwnProperty(key)) values.push(object[key]); } return values; }, getLength: function(object){ return Object.keys(object).length; }, keyOf: function(object, value){ for (var key in object){ if (object.hasOwnProperty(key) && object[key] === value) return key; } return null; }, contains: function(object, value){ return Object.keyOf(object, value) != null; }, toQueryString: function(object, base){ var queryString = []; Object.each(object, function(value, key){ if (base) key = base + '[' + key + ']'; var result; switch (typeOf(value)){ case 'object': result = Object.toQueryString(value, key); break; case 'array': var qs = {}; value.each(function(val, i){ qs[i] = val; }); result = Object.toQueryString(qs, key); break; default: result = key + '=' + encodeURIComponent(value); } if (value != null) queryString.push(result); }); return queryString.join('&'); } });

<1.2compat>

  1. 119
  2. 120
  3. 121
  4. 122
  5. 123
  6. 124
  7. 125
  8. 126
  9. 127
  10. 128
  11. 129
  12. 130
  13. 131
  14. 132
  15. 133
  16. 134
  17. 135
  18. 136
  19. 137
  20. 138
  21. 139
  22. 140
  23. 141
  24. 142
  25. 143
  26. 144
  27. 145
  28. 146
  29. 147
  30. 148
  31. 149
  32. 150
  33. 151
  34. 152
  35. 153
  36. 154
  37. 155
  38. 156
  39. 157
  40. 158
  41. 159
  42. 160
  43. 161
  44. 162
  45. 163
  46. 164
  47. 165
  48. 166
  49. 167
  50. 168
  51. 169
  52. 170
  53. 171
  54. 172
  55. 173
  56. 174
  57. 175
  58. 176
  59. 177
  60. 178
  61. 179
  62. 180
  63. 181
  64. 182
  65. 183
  66. 184
  67. 185
  68. 186
  69. 187
  70. 188
  71. 189
  72. 190
  73. 191
  74. 192
  75. 193
  76. 194
  77. 195
  78. 196
  79. 197
  80. 198
  81. 199
  82. 200
  83. 201
  84. 202
  85. 203
Hash.implement({ has: Object.prototype.hasOwnProperty, keyOf: function(value){ return Object.keyOf(this, value); }, hasValue: function(value){ return Object.contains(this, value); }, extend: function(properties){ Hash.each(properties || {}, function(value, key){ Hash.set(this, key, value); }, this); return this; }, combine: function(properties){ Hash.each(properties || {}, function(value, key){ Hash.include(this, key, value); }, this); return this; }, erase: function(key){ if (this.hasOwnProperty(key)) delete this[key]; return this; }, get: function(key){ return (this.hasOwnProperty(key)) ? this[key] : null; }, set: function(key, value){ if (!this[key] || this.hasOwnProperty(key)) this[key] = value; return this; }, empty: function(){ Hash.each(this, function(value, key){ delete this[key]; }, this); return this; }, include: function(key, value){ if (this[key] == null) this[key] = value; return this; }, map: function(fn, bind){ return new Hash(Object.map(this, fn, bind)); }, filter: function(fn, bind){ return new Hash(Object.filter(this, fn, bind)); }, every: function(fn, bind){ return Object.every(this, fn, bind); }, some: function(fn, bind){ return Object.some(this, fn, bind); }, getKeys: function(){ return Object.keys(this); }, getValues: function(){ return Object.values(this); }, toQueryString: function(base){ return Object.toQueryString(this, base); } }); Hash.extend = Object.append; Hash.alias({indexOf: 'keyOf', contains: 'hasValue'});

</1.2compat>