Ticket #7927 (closed bug: notabug)

Opened 18 months ago

Last modified 18 months ago

Widget inherits super widget properties

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

Description

If you make widget foo, and then widget bar which extends foo, the extended widget(foo) prototype will inherit its properties.

Precondition is the property must be an object, and must be empty on the base widget.

var meh = {
    foo:{},
    _create: function() { }
}
jQuery.widget('fd.meh',meh);

var moh = {
    foo:{bar:'bar'},
    _create: function() { }
}
jQuery.widget('fd.moh',jQuery.fd.meh,moh);

console.log(jQuery.fd.meh.prototype);

Change History

comment:1 follow-up: ↓ 2 Changed 18 months ago by scott.gonzalez

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

That's just how inheritance works. You're not going to get the expected results even without inheritance if you have an object in your prototype because every instance will be sharing the same object.

comment:2 in reply to: ↑ 1 Changed 18 months ago by mrubio

Replying to scott.gonzalez:

That's just how inheritance works. You're not going to get the expected results even without inheritance if you have an object in your prototype because every instance will be sharing the same object.

I expected them to be copied like options property.

comment:3 Changed 18 months ago by scott.gonzalez

Well, that actually happens in master (1.9pre), but you're still going to have every instance sharing the same object.

Note: See TracTickets for help on using tickets.