[jQuery] serializeHash() instead of serializeArray()

[jQuery] serializeHash() instead of serializeArray()


I need some help by a jQuery internals hacker, because I don't really
know how to add this particular feature that I need to jQuery:
Sometimes I want to serialize a form to a Hash/Object in the form of:
{ key: 'val', key2: 'val2' }
jQuery only gives me serializeArray(), which gives me something like
this which is rather awkward sometimes:
[ { name: 'key', value: 'val' }, { name: 'key2', value: 'val2' } ]
I use the following code to convert from an array like that to a Hash:
var new_item = $(this).serializeArray();
var new_item_hash = {};
$.each(new_item, function() {
new_item_hash[this.name] = this.value;
});
How do I take this and build a simple addon for jQuery that allows me
to do:
var new_item = $(this).serializeHash();
How do I do that?
Thanks,
Herb