Elegant?  Perhaps.

Breaks the Principle of Least Surprise?  Absolutely, unfortunately.

I'm with Chris.  One method that's always destructive, and another method
that's always not.

- Brian


> I thought, I'd add on my personal thoughts on this subject. Personally,
> I find the anonymous function version of filter et. al. to be quite
> intuitive. You can either modify the stack temporarily and continue the
> chain until you .end() this modified stack and return to the original,
> or you can simply apply the methods you want to the argument you
> provided leaving the original stack intact without needing to .end() the
> modified stack seeing as it wasn't modified. Please please keep this
> syntax as it's too elegant to not keep around.
>
> -blair
>
> Christof Donat wrote:
>> Hi,
>>
>>> [...]
>>> .method( Hash, arg1, ..., argN, ContextFunction )
>>> [...]
>>
>> That all was not my point. My point was that it is irritating that the
>> same
>> function may be destructive or not just by providing the
>> context-function.
>> I'd vote for either never be destructive, or always. Since for functions
>> like
>> filter() it is difficult to go the "never destructive"-way, I'd like it
>> to be
>> always destructive and have an alternative version which is never
>> destructive.
>>
>>> So, with .filter("foo",function) I'm taking the opportunity to remove
>>> the need for:
>>> .filter("foo").each(function(){
>>>
>>> }).end()
>>
>> That is exactly what the suggestet the filterend()-function is for. That
>> way
>> filter() ist always destructive and filterend() never. In both cases
>> with or
>> without a context function.
>>
>> $('div').filter('.test') // return value only contains divs with class
>> 'test'
>> $('div').filter('.test,  // return value only contains divs with class
>> 'test'
>>      function() {
>>              ...
>>      });
>> $('div').filterend('.test') // return value contains all divs (useless)
>> $('div').filterend('.test,  // return value contains all divs
>>      function() {
>>              ...
>>      });
>>
>> The last to calls have the same effect as
>>
>> $('div').filter('.test').end()
>> $('div').filter('.test').each( function() {
>>      ...
>> }).end();
>>
>> In all cases the context function is evaluated for each div with the
>> class 'test'. The difference between filter() and filterend() is just
>> the
>> return value.
>>
>> Christof
>>
>> _______________________________________________
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/
>
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>



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

Reply via email to