Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #11
    Sencha User
    Join Date
    Nov 2009
    Posts
    4
    Vote Rating
    0
    natelapp is on a distinguished road

      0  

    Default


    This seems like a fairly significant thing to me.

    I don't know that it's "simply how JavaScript prototypal inheritance work" especially since Ext is controlling it by adding everything to the prototype of the class instead of the individual instance. As it stands right now it appears to be automatically treating any object or array defined at the class level as a static. However, you've given the ability to define "statics" so I don't know why you wouldn't leverage that configuration when dealing with any property, including arrays/objects.

    Is this something that Sencha would be willing to reconsider?

  2. #12
    Sencha User mberrie's Avatar
    Join Date
    Feb 2011
    Location
    Bangkok, Thailand
    Posts
    507
    Vote Rating
    14
    mberrie will become famous soon enough mberrie will become famous soon enough

      0  

    Default


    I agree that this is indeed pretty puzzling for programmers coming from a different background and applying classic OOP principles and terms to prototype-based inheritance.

    However, in Javascript the only(?) way to allow a property to be inherited is to add it to the prototype.

    Javascript handles resolving properties on an object (like obj.property) and traverses the prototype chain to find a match if the object itself does not define it (result: inheritance)

    Any object can override the property by re-assigning a different value (this.property=..). The property will then be owned by that object alone.

    It has been pointed out in this thread before, that for immutable values the behavior appears to be that of classic-OOP class fields.
    The confusion starts once you do not *reassign* (override) the property value but manipulate/modify it.



    How could Ext provide a solution to this?

    Looking at classic OOP and compiled languages (or languages that have the construct of a 'class'), you have to consider that the code statement that defines the (default) value for a class field is re-evaluated each time an instance of the class is created.

    This is not possible in Javascript and in Ext.define(). The code statement that defines the value for the property will be evaluated exactly once and the *result* will be passed to Ext.define! The class object that Ext creates from the class definition cannot really imitate the behavior described above.
    One suggestion was to clone the object and assign a copy to every object that is created as instance of this class. But as I pointed out in my previous post, cloning only works for simple objects.



    hth

  3. #13
    Sencha User
    Join Date
    Nov 2009
    Posts
    4
    Vote Rating
    0
    natelapp is on a distinguished road

      0  

    Default


    That does make sense... even if I'm not happy about it...

    I can see how simply always doing a clone wouldn't necessarily be a good idea, especially if one of those properties happened to be a reference to some other instance.

    Well, I'm glad I came across this thread. And thanks for the detailed explanation. That could have made for some especially insidious bugs down the road.

  4. #14
    Sencha - Sencha Touch Dev Team Jacky Nguyen's Avatar
    Join Date
    Jul 2009
    Location
    Palo Alto, California
    Posts
    469
    Vote Rating
    13
    Jacky Nguyen has a spectacular aura about Jacky Nguyen has a spectacular aura about

      0  

    Default


    Compare these 2 pieces of code:

    Code:
    Ext.define('Foo', {
        bar: {
            baz: true
        },
        
        constructor: function() {
            this.bar = Ext.clone(this.self.prototype.bar);
        }
    });
    Code:
    Ext.define('Foo', {
        constructor: function() {
            this.bar = {
                baz: true
            };
        }
    });
    You will immediately find that it doesn't make sense sacrificing (huge) performance to clone to original object for every instance of Foo, instead of just creating a new one inside the class' constructor.
    Sencha Touch Lead Architect

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar