Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#8942 closed bug (notabug)

This scope ignored, during array push

Reported by: ultrdev Owned by:
Priority: minor Milestone: 1.10.0
Component: ui.widget Version: 1.9.2
Keywords: Cc:
Blocked by: Blocking:


I recently updated to the latest jquery ui code base 1.9.2 and jquery 1.8.3, and noticed that the 'this' scope is ignored during a js array push. The code previously worked in ui - 1.8.14 and jquery 1.7.1.

Please see for an example.

There are two test in there and you have to manually move the js comment tags.

The test 1 example js creates two different types of widgets: filterlist and filter. The filterlist widget creates 3 filter widgets during initialization. Initially, each filter widget has an options.selected value of a blank array array(). Then I call appendSelected in the first filter widget only, but it ignores the 'this' scope and modifies all of the filter options.selected value. You end up with all 3 of the filters have an options.selected value of array('test val'), which is incorrect. Only the first widget should have the updated value.

In test 2, I set the options.selected value to array('set val') and then call js push, and it correctly modifies the first filter options.selected to array('set val','test val'). Filters 2 and 3 correctly remain blank.

The issue occurs in all browsers (FF, Chrome and IE).

Change History (4)

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

Resolution: notabug
Status: newclosed

This is by design. You can't define an array as a default value. Arrays as options are now passed by reference, so that you can keep a local data store outside of the widget and have live updates.

See for a working version of your code (note the instantiation of the filter widgets).

Last edited 11 years ago by Scott González (previous) (diff)

comment:2 Changed 11 years ago by TheSharpieOne

When was this added? I just noticed it. I couldn't find it documented anywhere, but it seems like it is pretty important to know.

Also: not just options have to be passed, all arrays do. I store "internal" values (_value:) which have an empty array by default, these are now outside of the scope. (see console log: ) Was this intentional too?

comment:3 Changed 11 years ago by Scott González

You've never been able to define an array as a property on the prototype and have it be per-instance. That's just how JavaScript works. The only thing that changed is specific to options, where we switched from a deep copy to a shallow copy for arrays.

comment:4 Changed 11 years ago by TheSharpieOne

I guess I never realized that. It makes sense, Thanks!

Note: See TracTickets for help on using tickets.