Sorry Ariel, there is a logical chain error in my example, I'll prepare a
better one with a couple of Array prototypes and you'll deciede if it is
interesting or not, is it fine?
Regards
On Mon, Oct 27, 2008 at 9:21 AM, Andrea Giammarchi <
[EMAIL PROTECTED]> wrote:
> Ariel, thanks for the link, i quickly read it and it seems other people
> thought about that idea before.
> Anyway, my vision is more semantic and less complicated, since with a
> callback inside the if you can define many expressions, do operations, and
> then return true or false.
>
> What I mean is that your if().hasClass is limited to one or more jQuery
> operation, while if(callbackInScope) has no limits at all and inside you can
> return $(this).hasClass("whatever").
>
> In any case and for performances improvement, for the if else I would
> create a jQuery istance instead of callback
>
> this.if = jQuery(this);
> this.if._condition = 1; // as first condition to evaluate (make
> if(this._condition) check simpler)
>
> so te call will be something like
> $(elm).on("click")
> .if
> .hasClass('foo')
> .then()..
>
> As I said before, this implementation suffer about And or Or possibilities
>
> $(elm).on("click")
> .if
> .hasClass('foo')
> .And
> .text()
> .then()..
>
> as last limitation, you cannot compare properties:
>
> if.text() == "something"
>
> for this reason I suppose that the callback inside the If(whateverCallback)
> that as implementation will be simply a filter inside the method if
> something like
>
> If:function(fn){ // set first list of elements
> this._succeded = jQuery(this).filter(fn);
> return this._succeded;
> },
> ElseIf:function(fn){ // exclude precedent elements
> var _succeded = this._succeded,
> result = jQuery(this).filter(fn).filter(function(i, elm){return
> ~_succeded.indexOf(elm)});
> this._succeded =
> this._succeded.concat(Array.prototype.slice.call(result, 0));
> return result;
> },
> Else:function(){ // return only last list of elements
> var _succeded = this._succeded;
> returh this.filter(function(i, elm){return ~_succeded.indexOf(elm)});
> }
>
> I did not test above code, it is only to demonstrate the ligic behind. It
> does not seem to be that complicated but for sure it is more intense for CPU
> and could be more problematic for mem leaks
>
> Regards
>
>
> On Sun, Oct 26, 2008 at 11:42 PM, Ariel Flesler <[EMAIL PROTECTED]>wrote:
>
>> Andrea
>>
>> The if/else thing seems to make the code larger I think. If you need to
>> pass a lambda to If, then another to else of elseIf...
>>
>> It's an interesting idea and it came up before. I'm not so sure it's
>> brings clarity to code, though.
>>
>> Maybe .if().hasClass('foo').then()... but uhmm... seems to complicated.
>>
>> Here you have the old post I mentioned, maybe it gives you some cool idea
>> :)
>>
>> http://groups.google.com/group/jquery-en/browse_thread/thread/43a69fa41f6e7089/6cebfee318992fe6
>>
>> Brandon disagreed back then as well... that's a good thing I think :D
>>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---