Opened 10 years ago

Closed 10 years ago

#8721 closed feature (wontfix)

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'

Change History (1)

comment:1 Changed 10 years ago by Scott González

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.

Note: See TracTickets for help on using tickets.