I have two things to say:

1- Genius.
2- Seems like the byte saving is minimum. At this point, a regular if
would take exactly the same amount of code when minified (plus
the .end()'s) and it makes it harder to read, specially for non-
chaining-addicts (not my case).

In short, I love the idea, but doesn't seem so useful in the end.

Cheers

--
Ariel Flesler
http://flesler.blogspot.com

On 25 mar, 04:25, Guy Fraser <[EMAIL PROTECTED]> wrote:
> I've been playing with this...
>
> $.fn.if = function(flag) {
>     return (flag) ? this.pushStack( this ) : this.pushStack( [] );
>
> };
>
> You can then do stuff like:
>
> var addEdges = function(selector,opts) {
>    $('.selector)
>       .addClass('selected')
>       .if(opts.page>1)
>           .addClass('more-left')
>       .end()
>       .if(opts.page<opts.num_pages)
>           .addClass('more-right')
>       .end();
>
> }
>
> It's overkill, but having if statements in a jQuery chain makes for
> pleasant reading IMHO.
>
> My brain started to hurt when I tried adding ".else()" and also when I
> started thinking of "if ... else ... end" or things like "if ... else if
> ... end" and nesting, etc.
>
> Anyone got any ideas on how to extend my basic ".if()" ?
>
> Guy

Reply via email to