Side navigation
#6177 closed enhancement (wontfix)
Opened February 25, 2010 05:15PM UTC
Closed February 26, 2010 05:41PM UTC
Last modified February 26, 2010 06:21PM UTC
Enhance jQuery.extend() to allow option for each object to be a target respectively.
Reported by: | patrickwhalen | Owned by: | |
---|---|---|---|
Priority: | Milestone: | 1.4.4 | |
Component: | core | Version: | 1.4.1 |
Keywords: | extend() inheritance | Cc: | |
Blocked by: | Blocking: |
Description
Considering the following example:
a = {a: 'a'};
b = {b: 'b'};
c = {c: 'c'};
jQuery.extend(a, b, c);
...the result will be:
a = {a: 'a', b: 'b', c: 'c'};
b = {b: 'b'};
c = {c: 'c'};
...which is (and ought to be) the default behavior.
The enhancement would allow a flag to be set which modifies each object with the content of the ones which follow it, creating a true inheritance chain.
So, considering the modified example:
a = {a: 'a'};
b = {b: 'b'};
c = {c: 'c'};
jQuery.extend(a, b, c, true);
...the new result would be:
a = {a: 'a', b: 'b', c: 'c'};
b = {b: 'b', c: 'c'};
c = {c: 'c'};
...effectively doing something like:
var array = [a,b,c];
for(var i = (array.length - 2); i >= 0; i--) {
Query.extend(array[i], array[i+1]);
}
If the 'deep' parameter is set, it would of course need to set that parameter on the extend() in the 'for' loop.
Attachments (0)
Change History (2)
Changed February 26, 2010 05:41PM UTC by comment:1
component: | unfiled → core |
---|---|
resolution: | → wontfix |
status: | new → closed |
Changed February 26, 2010 06:21PM UTC by comment:2
Replying to [comment:1 john]:
Hmm, I disagree that this should be an option. It seems like it's easy enough to duplicate:> jQuery.extend( a, jQuery.extend( b, c ) ) >And this way there isn't any unintended (or unexpected) duplication.
That method works on my simple example because we know in advance how many objects there will be. Even if you did know, it would become unwieldy if there were too many more than 3 or 4.
The 'for' loop method seems to work just fine. Just thought it would make a nice shortcut to have the optional functionality. Not a big deal though, especially if you are concerned with cluttering the API with utilities that my not get too much use.
Hmm, I disagree that this should be an option. It seems like it's easy enough to duplicate:
And this way there isn't any unintended (or unexpected) duplication.