Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Ext User
    Join Date
    Dec 2007
    Posts
    10
    Vote Rating
    0
    ramaboo is on a distinguished road

      0  

    Default [2.2] function Ext.isEmpty - Unexpected behavior with objects

    [2.2] function Ext.isEmpty - Unexpected behavior with objects


    This is more of an unexpected behavior problem rather than a technical bug. The function Ext.isEmpty() does not work correctly when passed an object. I modified the Ext.isEmpty function as follows so that it will correctly return true for empty objects which is more inline with what I would expect.

    Code:
    function isEmpty(v, allowBlank) {
        if (typeof v === 'object' || typeof v === 'function') {
            var i;
            for (i in v) {
                if (v.hasOwnProperty(i)) {
                    return false;
                }
            }
            return true;
        } else {
            // not an object or function - same as before
            return v === null || v === undefined || (!allowBlank ? v === '' : false);
        }
    };
    I then created a series of tests with the following code:

    Code:
    var A = '';
    var B = null;
    var C;
    var D = {};
    var E = (function() {
        var private1 = 5;
        return {};
    })();
    var F = new Object;
    var G = [];
    var H = { someVal: 42 };
    var I = new Ext.Panel;
    
    
    if (Ext.isEmpty(A)) {
        console.debug('A is true');
    } else {
        console.debug('A is false');
    }
    
    if (Ext.isEmpty(B)) {
        console.debug('B is true');
    } else {
        console.debug('B is false');
    }
    
    if (Ext.isEmpty(C)) {
        console.debug('C is true');
    } else {
        console.debug('C is false');
    }
    
    if (Ext.isEmpty(D)) {
        console.debug('D is true');
    } else {
        console.debug('D is false');
    }
    
    if (Ext.isEmpty(E)) {
        console.debug('E is true');
    } else {
        console.debug('E is false');
    }
    
    if (Ext.isEmpty(F)) {
        console.debug('F is true');
    } else {
        console.debug('F is false');
    }
    
    if (Ext.isEmpty(G)) {
        console.debug('G is true');
    } else {
        console.debug('G is false');
    }
    
    if (Ext.isEmpty(H)) {
        console.debug('H is true');
    } else {
        console.debug('H is false');
    }
    
    if (Ext.isEmpty(I)) {
        console.debug('I is true');
    } else {
        console.debug('I is false');
    }
    
    console.debug ('Now the improved function');
    if (isEmpty(A)) {
        console.debug('A is true');
    } else {
        console.debug('A is false');
    }
    
    if (isEmpty(B)) {
        console.debug('B is true');
    } else {
        console.debug('B is false');
    }
    
    if (isEmpty(C)) {
        console.debug('C is true');
    } else {
        console.debug('C is false');
    }
    
    if (isEmpty(D)) {
        console.debug('D is true');
    
    } else {
        console.debug('D is false');
    }
    
    if (isEmpty(E)) {
        console.debug('E is true');
    } else {
        console.debug('E is false');
    }
    
    if (isEmpty(F)) {
        console.debug('F is true');
    } else {
        console.debug('F is false');
    }
    
    if (isEmpty(G)) {
        console.debug('G is true');
    } else {
        console.debug('G is false');
    }
    
    if (isEmpty(H)) {
        console.debug('H is true');
    } else {
        console.debug('H is false');
    }
    
    if (isEmpty(I)) {
        console.debug('I is true');
    } else {
        console.debug('I is false');
    }
    The results were as follows:
    A is true
    B is true
    C is true
    D is false
    E is false
    F is false
    G is false
    H is false
    I is false
    Now the improved function
    A is true
    B is true
    C is true
    D is true
    E is true
    F is true
    G is true
    H is false // correct
    I is false // correct


    As you can see the new function now correctly identifies empty objects (though it will say an object is empty even if it has private variables - E).

    I have tested the above function in my Ext application using Ext.isEmpty = isEmpty; with no problems so far.

    David
    All changes released to the public domain.

  2. #2
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    i re-read the API for Ext.isEmpty() thrice just to be sure, and i see no lack of clarity with the existing description (emphasis added):
    Returns true if the passed value is null, undefined or an empty string
    while your additions will prove useful to some, which part of the existing description is unclear?

    p.s. an empty js object does not constitute a null / undefined value, nor an empty string.

  3. #3
    Ext User
    Join Date
    Dec 2007
    Posts
    10
    Vote Rating
    0
    ramaboo is on a distinguished road

      0  

    Default


    I don't think the description is unclear. In fact i agree the function does exactly what it is described to do however i think that is somewhat counter intuitive to what one would expect from an isEmpty function.

    It just seems like (atleast to me) that an isEmpty function should return true for anything that is empty not just null, undefined and empty strings. If you google isEmpty most of the other helper libraries out there handle it this way.

  4. #4
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    i see. i'll leave this thread open for consideration by the dev team then.

  5. #5
    Ext User steve.neill's Avatar
    Join Date
    Mar 2007
    Posts
    99
    Vote Rating
    0
    steve.neill is on a distinguished road

      0  

    Thumbs up I agree...

    I agree...


    The documented definition of isEmpty() does not align with what you'd expect from "is empty".

    An object with no assigned property values or an array with zero elements (I think) should be considered "empty".

    I also overrode the Ext isEmpty function to do the same.

  6. #6
    Ext User
    Join Date
    Dec 2007
    Posts
    10
    Vote Rating
    0
    ramaboo is on a distinguished road

      0  

    Default


    steve.neill Will you post your function/make it public domain? I would be happy to test yours vs mine to see what one is faster?

Thread Participants: 2