>> var a = $H({
>>      a1: ["1", "2"],
>>      a2: ["3", "4"],
>> });
>> a.each(function(n) {
>>      var v = $H(n).value;
>>  });
>> 
>> how would I do this in jQuery?

> What does it do?

$H() is prototype's Hash creator. 
http://www.sergiopereira.com/articles/prototype.js.html#Reference.Hash

Here is the implementation:
http://dev.rubyonrails.org/browser/spinoffs/prototype/src/hash.js?rev=3429

Since jQuery doesn't touch Javascript's native Object the way prototype
does, you could easily use a bare object for this sort of thing.

var a = {
        a1: ["1", "2"],
        a2: ["3", "4"],
};
for ( var n in a ) {
  var v = a[n];
}

Or you could use a wrapper, something like this--incomplete and untested:

$H = function (obj) {
  var nh = {};
  nh.constructor = $H;
  nh.merge(obj);
  return nh;
};
$H.prototype.each = function(f) {
  for ( var i in this )
    if typeof(this[i]) != "function" ) f({key: i, value: this[i]});
};
$H.prototype.keys = function() {
  var k = [];
  for ( var i in this )
    if typeof(this[i]) != "function" ) k.push(i);
  return k;
};
$H.prototype.values = function() {
  var v = [];
  for ( var i in this )
    if typeof(this[i]) != "function" ) v.push(this[i]);
  return v;
};
$H.prototype.merge = function(h) {
  var nh = $H(h);
  this.each(function(e){
    if typeof(this[i]) != "function" ) 
      nh[e.key]=e.value;
  });
  return nh;
};


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to