> 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.

Can you explain which objects you expect would extend the final
object, and which object would not?
(nodes are objects too)

> 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 )

This is so wrong.
Maybe you can expect indexes in numerical order for Arrays, but still
Array.prototype is to often extended.
Also we have to iterate like sequence any array-like object (jQuery
objects, NodeLists,...).
.......

>
> > 3. for(var k in obj) newobj[k] = fn(obj[k])
>
> Like I said, it doesn't have the benefit of scoping.

If your argument is scoping, it is not enough.

--

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.


Reply via email to