I have a jquery widget like this:
$.widget("ui.MyWidget", {
options: {
Value1: 10,
Value1: 20,
},
// and other methods like _create,...
});
And, i am extending it like this:
$.widget("ui.MyExtWidget", $.extend({
options: {
Value3: 20,
}}, $.ui.MyWidget.prototype, {
myNewMethod: function(){
alert(this.options.Value1+this.options.Value3);
}
}
I have to call the "myNewMethod" in my html.
My html code is like this:
$("#Div1").MyExtWidget();
$("#Div1").MyExtWidget("myNewMethod");
I am getting exception like this while using the above code cannot call methods on TimeSpanHeader prior to initialization; attempted to call method 'myNewMethod'
What is the way to call the "myNewMethod" method?
The widget factory provides a way to extend from an existing widget with
$.widget
constructor:Note: The constructor will take care of extending the options as well. This is the method used in the jQuery UI library itself. For instance, the widget
ui.mouse
has options and a lot of the other widgets inherits from it and have their own extra options along with the ones from ui.mouse.DEMO
From the Widget Factory wiki post: