What do you think about chaining this way:

jQuery.callback = function(){
  var args = jQuery.makeArray(arguments);
  if(typeof args[0] == 'string' )
    args=[args];

  return function(){
    for(var i in args){
      fn = args[i].shift();
      jQuery.fn[ fn ].apply( jQuery(this), args[i] );
    }
  };
};

jQuery(function(){
        jQuery("#test").hide("slow",
                jQuery.callback( ["show", "slow"], ["addClass","done"] )
        );
});

?

On Oct 5, 3:18 pm, "John Resig" <[EMAIL PROTECTED]> wrote:
> I already did it:http://dev.jquery.com/~john/plugins/callback/
>
> my other proposal:http://dev.jquery.com/~john/plugins/callback/old.html
>
> I'm working on a third proposal now.
>
> A nice thing about $.callback is that it's very simple (perhaps too
> simple - no support for chaining).
>
> --John
>
> On Sat, Oct 4, 2008 at 7:09 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote:
> > Why don't we make a plugin out of this ? there's no so much of a need for
> > this on the core.
> > Then, if it seems successful, we can add it (just like offset/dimensions).
>
> > On Sat, Oct 4, 2008 at 4:26 PM, Brandon Aaron <[EMAIL PROTECTED]>
> > wrote:
>
> >> Although it seems like we are getting further off-topic... I often pass
> >> around function references as strings. For example this is a common pattern
> >> that I use.
> >> $('div')[ test() ? 'doSomething' : 'doSomethingElse' ]();
> >> Using something like $.callback is very explicit as to its purpose. After
> >> all callback is exactly what we call it in the docs, etc. Granted I don't
> >> mind using anonymous callbacks, if I need the code to be cleaner, I'll use
> >> named functions to be even more explicit. But of the other proposals I like
> >> $.callback the best.
> >> --
> >> Brandon Aaron
> >> On Sat, Oct 4, 2008 at 9:56 AM, Cloudream <[EMAIL PROTECTED]> wrote:
>
> >>> I do not like passing a jQuery method name as a string to one special
> >>> method.
>
> >>> A new (and a little strange) usage to jQuery.
>
> >>> On Oct 4, 5:06 am, "Brandon Aaron" <[EMAIL PROTECTED]> wrote:
> >>> > I'd prefer this as well.
>
> >>> > I think this also helps a few common cases of var self = $(this);
> >>> > --
> >>> > Brandon Aaron
>
> >>> > On Fri, Oct 3, 2008 at 4:01 PM, Yehuda Katz <[EMAIL PROTECTED]> wrote:
> >>> > > $.callback("addClass", "hello") is ok with me.
> >>> > > -- Yehuda
>
> >>> > > On Fri, Oct 3, 2008 at 1:58 PM, Ariel Flesler <[EMAIL PROTECTED]>
> >>> > > wrote:
>
> >>> > >> Yeah, well. We could provide an interface for registering these
> >>> > >> methods
> >>> > >> for those plugins that are interested. Still, someone could expect a
> >>> > >> method
> >>> > >> to be registered when it's not.
>
> >>> > >> The other option is to pass the method name as first argument, works
> >>> > >> around this but it loses the I-call-the-analog-method thing.
>
> >>> > >> On Fri, Oct 3, 2008 at 5:51 PM, Yehuda Katz <[EMAIL PROTECTED]>
> >>> > >> wrote:
>
> >>> > >>> The only tricky thing here is that because JS has no method_missing
> >>> > >>> or
> >>> > >>> cross-browse __noSuchMethod__, we'd be forced to explicitly write
> >>> > >>> all the
> >>> > >>> proxies, which could become messy when they work for core methods,
> >>> > >>> but not
> >>> > >>> all plugins.
> >>> > >>> Or maybe I'm just being a nervous nelly.
>
> >>> > >>> -- Yehuda
>
> >>> > >>> On Fri, Oct 3, 2008 at 1:46 PM, Ariel Flesler
> >>> > >>> <[EMAIL PROTECTED]>wrote:
>
> >>> > >>>> Note that John's code doesn't do actual currying, but partial
> >>> > >>>> evaluation.
>
> >>> > >>>>http://en.wikipedia.org/wiki/Partial_evaluation
>
> >>> > >>>> Currying is a complex concept in comparison to the latter.
> >>> > >>>> Anyway, you can change the name if you want, the idea is simple,
> >>> > >>>> create
> >>> > >>>> a closure with fixed parameters.
> >>> > >>>> We can name it callback (though it's long)
>
> >>> > >>>> jQuery("#test").hide("slow", jQuery.callback.show("slow") );
>
> >>> > >>>> Not to hard to understand IMO, and no CS involved :)
>
> >>> > >>>> On Fri, Oct 3, 2008 at 5:41 PM, Yehuda Katz <[EMAIL PROTECTED]>
> >>> > >>>> wrote:
>
> >>> > >>>>> As in Computer Science.
> >>> > >>>>> Using a currying function requires people new to jQuery to go
> >>> > >>>>> look it
> >>> > >>>>> up, where they'll encounter:
>
> >>> > >>>>>http://en.wikipedia.org/wiki/Curry
>
> >>> > >>>>> and probably eventually:
>
> >>> > >>>>>http://en.wikipedia.org/wiki/Currying
>
> >>> > >>>>> "Given a function *f* of type [image: f \colon (X \times Y) \to
> >>> > >>>>> Z],
> >>> > >>>>> then *currying* it makes a function [image: \mbox{curry}(f)
> >>> > >>>>> \colon X
> >>> > >>>>> \to (Y \to Z)]. That is, curry(*f*) takes an argument of type *X*
> >>> > >>>>> and
> >>> > >>>>> returns a function of type [image: Y \to Z].*Uncurrying* is the
> >>> > >>>>> reverse transformation."
>
> >>> > >>>>> Prototype added features like this to 1.6, and while they're
> >>> > >>>>> interesting and useful, they make it hard for people coming to a
> >>> > >>>>> codebase
> >>> > >>>>> (especially people new to the framework) to understand what's
> >>> > >>>>> happening in
> >>> > >>>>> the code.
>
> >>> > >>>>> On Fri, Oct 3, 2008 at 1:34 PM, Ariel Flesler
> >>> > >>>>> <[EMAIL PROTECTED]>wrote:
>
> >>> > >>>>>> CS as in Counter Strike ? :D
> >>> > >>>>>> Heh, no really... what is CS, forgive my ignorance :P
>
> >>> > >>>>>> On Fri, Oct 3, 2008 at 5:30 PM, Yehuda Katz <[EMAIL PROTECTED]>
> >>> > >>>>>> wrote:
>
> >>> > >>>>>>> Any feature that requires knowledge of CS is a no-go in my book
> >>> > >>>>>>> :P
> >>> > >>>>>>> -- Yehuda
>
> >>> > >>>>>>> On Fri, Oct 3, 2008 at 1:27 PM, Ariel Flesler
> >>> > >>>>>>> <[EMAIL PROTECTED]>wrote:
>
> >>> > >>>>>>>> Eh, nothing, got it wrong.
>
> >>> > >>>>>>>> We could just save all these methods on a special object.
>
> >>> > >>>>>>>> jQuery("#test").hide("slow", jQuery.curry.show("slow") );
>
> >>> > >>>>>>>> The name could be changed of course.
>
> >>> > >>>>>>>> Or renamed methods (probably bad option)
>
> >>> > >>>>>>>> jQuery("#test").hide("slow", jQuery.curriedShow("slow") );
>
> >>> > >>>>>>>> On Fri, Oct 3, 2008 at 5:14 PM, John Resig
> >>> > >>>>>>>> <[EMAIL PROTECTED]>wrote:
>
> >>> > >>>>>>>>> > It is indeed. You can't expect parameters though and you
> >>> > >>>>>>>>> > could
> >>> > >>>>>>>>> get conflict
> >>> > >>>>>>>>> > with the actual parameters sent by the caller.
>
> >>> > >>>>>>>>> I'm not sure what you're referring to - are you referring to
> >>> > >>>>>>>>> a bug
> >>> > >>>>>>>>> in
> >>> > >>>>>>>>> the code? Do you have an example?
>
> >>> > >>>>>>>>> --John
>
> >>> > >>>>>>>> --
> >>> > >>>>>>>> Ariel Flesler
> >>> > >>>>>>>>http://flesler.blogspot.com
>
> >>> > >>>>>>> --
> >>> > >>>>>>> Yehuda Katz
> >>> > >>>>>>> Developer | Engine Yard
> >>> > >>>>>>> (ph) 718.877.1325
>
> >>> > >>>>>> --
> >>> > >>>>>> Ariel Flesler
> >>> > >>>>>>http://flesler.blogspot.com
>
> >>> > >>>>> --
> >>> > >>>>> Yehuda Katz
> >>> > >>>>> Developer | Engine Yard
> >>> > >>>>> (ph) 718.877.1325
>
> >>> > >>>> --
> >>> > >>>> Ariel Flesler
> >>> > >>>>http://flesler.blogspot.com
>
> >>> > >>> --
> >>> > >>> Yehuda Katz
> >>> > >>> Developer | Engine Yard
> >>> > >>> (ph) 718.877.1325
>
> >>> > >> --
> >>> > >> Ariel Flesler
> >>> > >>http://flesler.blogspot.com
>
> >>> > > --
> >>> > > Yehuda Katz
> >>> > > Developer | Engine Yard
> >>> > > (ph) 718.877.1325
>
> > --
> > Ariel Flesler
> >http://flesler.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to