JQuery - Widget Public Methods

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-05-05T17:20:04Z Indexed on 2010/05/06 12:38 UTC
Read the original article Hit count: 119

Filed under:
|

If I create a JQuery widget (code example below), and then define a "public" method, is there any other way to call the method other than using the following form?

$("#list").list("publicMethod"); 

I would like to create a series of widgets that all define the same methods (basically implementing the same interface), and be able to call the method without knowing anything about which widget I currently am invoking the method on. In the current form, I need to know that I am executing the method on the "list" widget.


Below is an example of creating a widget with the "public" method.

 (function($) {
    var items = [];
    var itemFocusIdx = 0;

    $.widget("ui.list", {
        // Standard stuff
        options : { ... },
        _create : function() { ... },
        destroy : function() { ... },

        // My Public Methods
        publicMethod : function() { ... }
        ...
    });
}(jQuery));

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui