On Jun 2, 1:06 pm, ajpiano <[email protected]> wrote:
> Over the years there has been considerable interest in providing
> conditional chaining functionality to jQuery, though nothing has ever
> been cemented.
I still don't understand the desire to do all this chaining. How is it
at all beneficial?
You take perfectly readable javascript code like this:
var elem = $('div');
elem.append( '1' );
if ( my_test( 'foo' ) ) {
elem.append( '2' );
}
elem.append( '3' );
and turn it into less-readable, jquery-specific, less-maintainable
code like this:
$('div')
.append( '1' )
.iff( my_test, 'foo' )
.append( '2' )
.end()
.append( '3' );
Same number of lines, but you've made it more cryptic and less
javascripty. How is this a good thing?
As part of my "jQuery Best Practices" I recommend that developers
never chain across multiple lines. I always encourage assigning $()
calls to a variable, then using that variable.
Any line beginning with a . should be discouraged, IMO.
Just my $.02...
Matt Kruse
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---