I’m trying to set up a parent class that extends a subclass, but whenever I attempt to reference this.element in the subclass when called from the superclass, it’s undefined. What am I doing wrong here?
$.widget("ui.testSuper", $.extend({}, $.ui.testSub.prototype,
{
_init: function ()
{
$.ui.testSub.prototype._init();
},
...
}));
$.widget("ui.testSub", $.ui.mouse,
{
_init: function ()
{
this.element.addClass("some-class");
},
...
});
$('#some-element').testSub({ }); // this works fine
$('#some-element').testSuper({ }); // this.element is undefined
When you extend
$.ui.testSubit doesn’t exists at those point. All you need to do is to swap those two blocks of code:See live example here
UPDATE
I got what you’re saying. You need to call base method like this
So you will not loose the context of your element. Example is here