Skip to main content

Search and Top Navigation

#8721 closed feature (wontfix)

Opened October 23, 2012 08:10PM UTC

Closed October 23, 2012 08:13PM UTC

Widget subclass abstraction

Reported by: shuoink Owned by:
Priority: minor Milestone: 1.10.0
Component: ui.widget Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:
Description

I'm working with one base widget that has a number of different sub-widgets and am having difficulty with abstraction. I would like to be able to call a function of a widget even if I don't know the widget's name. In other words, I want to be able to write this:

$element.base_widget('myfunction');
. Right now, that throws an exception because it's looking for an instance of the base widget and ignoring widgets that inherit from the base widget.

  // define two widgets, one as a subclass of the other:
  $.widget('foo.bar', { identify: function() { return 'bar'; } });
  $.widget('foo.baz', $.foo.bar, { identify: function() { return 'baz'; } });

  $a = $('<a />');
  $a.baz();
  $a.baz('identify');
  // => returns 'baz'
  $a.bar('identify');
  // => expected: return 'baz'
  // => actual: throws exception: Error: cannot call methods on foo prior to initialization; attempted to call method 'identify'
Attachments (0)
Change History (1)

Changed October 23, 2012 08:13PM UTC by scottgonzalez comment:1

resolution: → wontfix
status: newclosed

There's no sane way to handle this. See https://forum.jquery.com/topic/widget-inheritance-no-polymorphism for a related discussion.