A Compilation of YUI Callback

I have been coding JavaScript with YUI for quite a while now. Still, I am consistently confused by various callback functions in YUI. The thing that troubled me the most was the parameters those callback functions take. The API documentation does not provide any information about this. For example, if you go to YAHOO.util.Event, under addListener method, the description for parameter fn as follow: <Function> The method the event invokes.

Yes, it's a straightforward description, but it doesn't help too much. What I really need is the signature of this callback function. For the purpose of my own use, and to benefit the community, I decided to make a compilation of callbacks in YUI.

Callback for Native Browser Events

e - Name of the event fired.
o - Object that passed as a parameter to the callback function.

Callback for Custom Events

Depending on how the custom event is fired, the parameters that the callback function receives varies.

If the custom event is fired with parameter signature YAHOO.util.CustomEvent.LIST, which is by default, the parameters the callback function receives will be:

e - Name of this custom event.
a - Arguments that passed to the fire method of this event.
o - Object that passed as a parameter to this callback function.

If the custom event is fired with parameter signature YAHOO.util.CustomEvent.FLAT, the callback function receives two arguments:

a - First argument that passed to fire method of this event
o - Object that passed as a parameter to the callback function

Callback for Connection Manager

This is not a callback function, rather it's a callback object that contains two callback functions. You can pass additional parameters to each callback function through argument field of this object. To access this filed inside of the callback function, use o.argument.

Above are the callbacks I can think of so far. If you have any suggestion, feel free to post it in the comment section.

6 Comments A Compilation of YUI Callback

  1. Pingback: YUI Based Lightbox - Final : Code Central

  2. Ed Lincoln

    But what is the point. What would be a real world example of passing foo and bar to handleSuccess()

    var callback =

  3. okey

    var callback =
    success: function(o) {//do something},
    failure: function(o) {//do something},
    argument: {name:"YUI"}

    awasome thanks !!!

Comments are closed.