> 1. $.map() is not a real "general purpose" map function. If callback > returns an array then its items will be values because in same cases > it is convenient that a callback can returns multiple values. So if > you make $.map() generic for all "hashes" than you would $.map() > generic for all sequences too.
Yes, $.map() could work for hashes like this: var hash = { a: 1, b: 2 } $.map( hash, function( val, key ) { if( key === 'a') return { c: 3, d: 4 }; else return val; }); And now hash is { c: 3, d: 4, b: 2 }. It doesn't conflict with anything. > 2. If you make $.map() working with "hashes" too, then you have to > detect which object is a "hash" and which is a sequence. The only > think to do that is to check if the object.length is a number - weak! Actually, you don't have to differentiate between hashes and sequences in js: if( typeof arr === 'object' ) for( var key in arr) For sequences, the key will be 0, 1, 2 and so on. If you want to be strict, you can rule out regexps: if( typeof arr === 'object' && arr.constructor !== RegExp ) > 3. for(var k in obj) newobj[k] = fn(obj[k]) Like I said, it doesn't have the benefit of scoping. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.