Cómo pasar un objeto JS a la función jQuery .queue ()

I use OOP and jQuery in my developments. I used to passed my current object this to jQuery functions like this :

$(myElement).live('click', this, function(el){
  // I can access to my JS object using el.data
});

But I can't find how to do similar thing with jQuery function .queue(). Is it possible ?

EDITAR

I give you the context in which I want to use .queue() :

CAPTIVEA.widget.Message = {
    /**
     * Displays generated message on the screen
     * @method display
     * @public
     */
    display: function() {
        // Display Message
        $('.message')[this.effects.show](this.effects.duration, function(){
            $(this).show();
            $('.message span').show();
            $('.message').children().show();
        });

        if (this.autoHide)
        {   // Remove message after delay
            $('.message').data('objMessage', this);
            $('.message').delay(3000).queue(function(el){
                $(this).data('objMessage').close();
            });
        }
    },

    /**
     * Removes generated message from the screen
     * @method close
     * @public
     */
    close: function() {
        $('.message')[this.effects.hide](this.effects.duration, function(){
            $(this).remove();
        });
    }
};

preguntado el 01 de febrero de 12 a las 14:02

Te refieres a $(myElement).queue(function(el){});? Cos that's possible... -

Que tipo de objeto hace this represent in your code? -

@am not i am : it is the object literal. Code example which I gave you is in a method of this object -

Como estas usando .queue(). That method just operates on whatever jQuery object it happened to be called from. Do you need this data associated with a particular element, or set of elements? If so, have you considered $.data()? -

@am not i am : I have edited my post to give you context. -

4 Respuestas

"Is it possible ?"

No. El live() method is an event handling method, and you're setting event object data. The first argument in the callback is the evento objeto.

No se que this represented, but I have a feeling you were misusing event data.

El queue() method has nothing to do with event handling. You pass it a function that is added to a queue. Its first parameter will reference a function that releases the queue.

Respondido 01 Feb 12, 18:02

You can still access the current object. See my jsfiddle here: http://jsfiddle.net/9upJB/

Aside from that, what others have pointed out is correct. live() (which you should STOP using btw) is an event. queue() is a method and has nothing to do with an event.

When accessing the object, this is executed as the callback (check the jQuery documentation).

Respondido 01 Feb 12, 18:02

you first save the instance as element data and use it in queue function of jquery;

$("#el").data("instance", this);

en after that use in the function

$("#el").queue(function(){
    var instance = $(this).data("instance");
    //do whatever you want
});

Respondido 01 Feb 12, 18:02

No pasas el queue() function the element instead the function is executed on the matched element.

$('yourelement').queue(); 

Respondido 01 Feb 12, 18:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.