Mar, I like the generality of .run, that's a great method. And I think
that it's a great example of something that should be integrated in
core, because of its utility, size and simplicity.
As I was working on .cond, I did notice that this:
.cond( test, callback,
test, callback,
callback )
looked an awful lot like
function() {
test ? callback()
: test ? callback()
: callback();
};
but I clearly didn't think quite enough of it to take it to the next
level. I do still feel that .iff has a very "jQuery" feel.. but it's
just not as appropriate as .run.
- Cowboy
On Jun 11, 5:14 am, Már <[email protected]> wrote:
> > It doesn't do the same thing. Where .each runs the tests for every
> > element in the collection and returns the collection, .cond() runs the
> > tests once and returns anything you like.
>
> Might I then suggest a simpler and more versatile method:
>
> jQuery.fn.run = function (func, args)
> {
> this.length && func.apply(this, args||[]);
> return this;
> },
>
> Used so:
>
> jQuery('a').run(function(){
> x === 1 ?
> this.css({ color: 'blue' }):
> x === 2 ?
> this.css({ color: 'red' }):
> test() ?
> this.css({ color: val }):
> this.css({ color: 'green' });
> });
>
> this `.run()` method has become part of my standard utility toolkit.
> Highly efficient (only runs if the collection has length>0) and
> provides the collection itself as this.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---