Ticket #8283 (closed bug: wontfix)

Opened 13 months ago

Last modified 13 months ago

Widgets should be accessible via ancestor names also

Reported by: fooblah Owned by: fooblah
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: 1.8.19
Keywords: Cc:
Blocking: Blocked by:

Description

Because: otherwise there is no way to get polymorphic behavior which is super nice.

For example:

$.widget('foo.myWidget' {
  doCoolThing: function () {}
})
$.widget('foo.specialWidget' $.foo.myWidget, {
  doOtherCoolThing: function () {}
})

$('.thing:not(.special-thing)').myWidget()
$('.thing.special-thing').specialWidget()

I want to be able to do:

$('.thing').each(function (i,el) {
   $(el).myWidget('doCoolThing');
});

But I can't (can I?). Instead I have to track these special cases everywhere in my code, not just where the differences matter which really sort of break a central feature of the entire notion of inheritance and classes.

I realize I can get direct references to the widgets and put them in an array or something but that that sucks is the entire point of the widget bridge.

Other hacky alternative:

  • make all public widget methods available at $('.foo').winst('someMethod')? And just let multiple widgets attached to same element clobber each other...

Change History

comment:1 in reply to: ↑ description Changed 13 months ago by scott.gonzalez

  • Owner set to fooblah
  • Status changed from new to pending

This is about way more than just what method name you use to access the plugin. For example, all event names change, and we're certainly not going to double up on those. Is there a reason why you can't just extend the widget instead of inheriting?

comment:2 Changed 13 months ago by fooblah

  • Status changed from pending to new

About extending, how exactly would that work in the example I provided? Do you mean after instantiating I would then mix-in specialWidget methods into instances that needed them?

comment:3 Changed 13 months ago by scott.gonzalez

  • Status changed from new to pending

In 1.8, just modify the prototype, e.g., $.foo.myWidget.newMethod = .... In 1.9, just inherit from yourself, e.g., $.widget( "foo.myWidget", $.foo.myWidget, { ... })

comment:4 Changed 13 months ago by fooblah

  • Status changed from pending to new

But then wouldn't all myWidget basically become specialWidgets? The idea is that the behavior of *some* instances is modified. If I do that then they will all act the same right? Or is there some way to do this in a limited context where only some instances will be affected?

comment:5 Changed 13 months ago by scott.gonzalez

  • Status changed from new to closed
  • Resolution set to wontfix

Yes, it would modify all, which is fine based on your example. I'm going to close this ticket. If you'd like to discuss actual uses cases, please start a discussion on the  Developing jQuery UI forum.

comment:6 Changed 13 months ago by fooblah

$.widget('foo.myWidget' {
  doCoolThing: function () {}
})
$.widget('foo.specialWidget' $.foo.myWidget, {
  doCoolThing: function () { this._super(); this._extraCoolStuff(); }
})

$('.thing:not(.special-thing)').myWidget()
$('.thing.special-thing').specialWidget()

This won't work and extending myWidget also wont work:

$('.thing').each(function (i,el) {
   $(el).myWidget('doCoolThing');
});
Note: See TracTickets for help on using tickets.