Just to adding my vote.

I like Johns approach because it fits in with the style of other jQuery methods. All the event and attribute methods have two sided functionality (bind/unbind, set/get), so it makes sense that the filtering methods would also have two sided functionality (persistent filter/non-persistent filter).

Blair

On 10/3/06, John Resig <[EMAIL PROTECTED]> wrote:
See, the important point, and the reason why I made this addition, is
for the fact that I'm trying to standardize how jQuery works and the
order of arguments for a method. The idiom that I'm molding is:

.method( Hash, arg1, ..., argN, ContextFunction )

If a method takes  a hash, you'll know that it's the first thing in
there. If it takes a context function - it'll always be last. With
that in mind, adding on context functions to virtually all methods
just makes  sense (we were nearly there to begin with).

This way, a user can call .load(), .submit(), .parent(), .find(), etc.
etc. and know that the last argument can be an optional function that
will be executed within the set's context.

So, with .filter("foo",function) I'm taking the opportunity to remove
the need for:

.filter("foo").each(function(){

}).end()

Which is good because it's very common, and way too verbose. It's also
the same reason why I added the context function to $(...), to remove
that common .each() need. When people write the above code, they're
effectively building a non-destructive area in which they can work.
And it makes sense that way.

A lot of what you're doing can depend on how you write your code too,
and how you indent it, for example:

$("div.test")
    .find("ul", function(){
        $(this).hide()
        if ( $("#newList:hidden").length )
            $("#newList").show('fast');
    })
    .find("form")
        .submit(function(){
            return false;
        })
    .end();

I'm not confused by the above, although, I am steeped in the code
pretty good, so who knows. Comments are definitely appreciated.

--John

On 10/3/06, Christof Donat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > I don't know, I've been using .filter( "foo", Function ) and .find(
> > "foo", Function ) for a while now and I find them to be immensely
> > useful - especially considering that they're non-destructive.
>
> Well, if it was destructive it would be more consistent. I don't think that it
> would be a problem, because you always have end():
>
>  $('.hideme').hide().filter('.showme').show().end().addclass('IamCrazy');
>
> is currently equivalent to
>
>  $('.hideme').hide().filter('.showme', function() {
>         $(this).show();
>  }).addclass('IamCrazy');
>
> It feels a bit odd to me. I'd expect this to be equal to the first line:
>
>  $('.hideme').hide().filter('.showme', function() {
>         $(this).show();
>  }).end().addclass('IamCrazy');
>
> The Problem arises when chaining a lot of filter(), find(), etc. functions.
> Then your way is IMO less readable.
>
> How about shortcut-functions for e.g. filter().end():
>
>  $.fn.filterend = function(s,c) { return this.filter(s,c).end(); }
>
>  $('.hideme').hide().filterend('.showme', function() {
>         $(this).show();
>  }).addclass('IamCrazy');
>
> I think that would be less confusing.
>
> Just my 2 cents.
>
> Christof
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>


--
John Resig
http://ejohn.org/
[EMAIL PROTECTED]

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to