Opened 10 years ago

Closed 10 years ago

#9382 closed bug (notabug)

Widget array member property (non-option) shared between instances

Reported by: AMA3AMA3 Owned by:
Priority: minor Milestone: none
Component: ui.widget Version: 1.10.3
Keywords: Cc:
Blocked by: Blocking:

Description

When a widget is defined having an array as a (non-option) member, the member is shared between instances. When defined as null and then assigned to an array in _create, each instance gets its own.

http://jsfiddle.net/u4ar3/

Happens w/jQUI 1.10.3 in IE10, FF21, Chrome 27 and Opera 12.15. Also happens in the jsfiddle using jQUI 1.9.2.

This is somewhat similar to #8645 but does not involve options; therefore, I believe that this issue should be treated differently.

Change History (1)

comment:1 Changed 10 years ago by tj.vantoll

Resolution: notabug
Status: newclosed

The object you pass as the last argument to $.widget is an object to be used as the prototype of the widget, which, by definition means that it will be shared across all instances. If you want an array that is instance specific you should only define it in _create() and avoid setting any arrays on the prototype.

$.widget( "foo.bar", {
    _create: function() {
        this._array = [];
    }
});
Note: See TracTickets for help on using tickets.