> From: ~flow
> 
> the second suggestion does work; however, the 
> pre-incrementing index has to be written as a 
> post-incrementing index, like this:
> 
>   var t = $( '.foo' );
>   var s = t;
>   t[ t.length++ ] = $Q( '.bar' )[ 0 ]; // should now like 
> like $ ( '.foo,.bar' )
>   assert( s === t, 'object identity broken' )
> 
> because we need exactly `t.length` as the target index, as 
> indices start at 0. (jQuery, unlike the standard Array 
> object, would not appear to accept assignments to unassigned 
> indices greater than the length of the object; if done, the 
> result is an `undefined`  value augmented to the jQuery 
> object, but the assignment's right hand side gets lost.)

That can't possibly be right (the part in parentheses). I think you're
misunderstanding a fundamental bit of JavaScript.

I didn't see what code you tried that failed, but if you still have it and
want to understand the *real* reason it failed, post it and I'll explain it.

If it's the code from Ricardo's message:

$foo[ ++$foo.length ] = $('.bar')[0];

then you're right, that needs to use a postincrement. But the reason it
doesn't work as expected is simply that it assigns into an array element
index one greater than it should.

-Mike

Reply via email to