Say you create a widget called my_widget and instantiate i开发者_StackOverflow中文版t on my_div as such:
jQuery('#my_div').my_widget()
Suppose my_widget has a do_something method. According to the widget factory documentation you would access do_something like:
jQuery('#my_div').my_widget('do_something', ['arg1','arg2'])
That's proving to be pretty cumbersome. It's error prone since if for some reason my_div doesn't yet have a widget, jQuery UI simply creates a new instance if you try to run do_something. Is there a better way?
Ideally there should be a way to say:
widget = jQuery('#my_div').my_widget('get_instance')
...
widget.do_something('arg1', 'arg2')
Is there anything like get_instance built-in?
If you read jQuery Plugin Authoring you'll see that this is the standard way to invoke a function within a plugin, and typical implementations provide no way to expose those functions as normal methods.
精彩评论