1. #1
    Ext JS Premium Member
    Join Date
    Jul 2009
    Posts
    27
    Vote Rating
    0
    extbio is on a distinguished road

      0  

    Default Ext.apply problem

    Ext.apply problem


    I think Ext.apply is having incorrect behavior based on documentation. For example, if you have:
    Code:
    var o = {a:1,c:3}, c = {a:3}, d = {c:5};
    Ext.apply(o, c, d);
    for(i in o) alert(i + ':' + o[i]);
    For the code above, most users probably would expect o == {a:3,c:3}, but instead the result is o == {a:3,c:5}. The defaults in Ext.apply actually overwrites existing values inside object. While it's arguable what should be the "correct" behavior here, the most commonly accepted rule in most programming situations is that default does not overwrite existing keys in object. This is the behavioral difference b/w defaults and config. Otherwise the default should be called config1, while the config be called config2.

    This also creates a byproduct issue where if you pass Ext.apply(o, o, d), supposedly new o should == old o for all keys, but instead after the call new o == d for the keys they share.

    Another issue is that only shallow copy's used here, so if user expected otherwise it would be an issue. That's not a bug, but a nice-to-note in documentation.

  2. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    There is Ext.applyIf

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2009
    Posts
    27
    Vote Rating
    0
    extbio is on a distinguished road

      0  

    Default


    One needs to call Ext.applyIf(o, d) then Ext.apply(o, c) to do what Ext.apply(o, c, d) is supposed to do, clearly applyIf is not ideal here.

    BTW I think this post should be removed - I didn't even know it was posted (I tried to post to Ext bug, but for some reason mods posted it to Ext help without notifying me), so I posted in Ext bug again. So this is a duplicate thread now.

  4. #4
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    It's not a bug because the behavior that you dislike is the intended behavior.

  5. #5
    Ext JS Premium Member
    Join Date
    Jul 2009
    Posts
    27
    Vote Rating
    0
    extbio is on a distinguished road

      0  

    Default


    Quote Originally Posted by jgarcia@tdg-i.com View Post
    It's not a bug because the behavior that you dislike is the intended behavior.
    I've heard that one from Microsoft before.

    I agree with Jamie's reply from http://www.extjs.com/forum/showthrea...Wrong-Behavior, if it ain't a bug in the code, then it's a bug with documentation. Fixing either one is fine - but don't tell me that in programming, the intended behavior of "defaults" is to overwrite existing values.

Thread Participants: 1

Tags for this Thread