David Fraser
David Fraser

Reputation: 7468

Call grandparent method in dojo with this.inherited

I'm trying to make a customized subclass of a dojo widget (the parent, dojox.mobile.ListItem, which derives from the grandparent, dijit._WidgetBase) .

One of the methods that I want to override and modify from the parent contains a call to this.inherited(arguments). This means that I can't just copy it directly into my subclass (because the this.inherited call from my method will call the parent class's method, not the grandparent's, as it did in the original context). I don't want to call the parent class's method as I'm deliberately adjusting what it does (I want to create different DOM elements to what ListItem creates). But I want to retain the standard grandparent class functionality, as ListItem does.

So I would like to call the grandparent class's method directly on the current object. Is there a way to do this? If not, how can I work around this problem?

Upvotes: 4

Views: 3794

Answers (1)

Craig Swing
Craig Swing

Reputation: 8162

Using dijit._WidgetBase.prototype.methodName() will lose the scope of the child widget, which may or may not have consequences. You should use

dijit._WidgetBase.prototype.methodName.apply(this, arguments)

Here is a fiddle to show what I mean

http://jsfiddle.net/cswing/4nGCH/

Upvotes: 3

Related Questions