Threaded View

    You found a bug! We've classified it as EXTJS-7491 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,325
    Vote Rating
    114
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default object.hasOwnProperty usage

    object.hasOwnProperty usage


    I think the way the hasOwnProperty method is used in Ext JS is not very efficient.

    See my modification below. The new code avoids long property lookups all the way to Object by caching the hasOwnProperty method in a local variable. This should improve performance.

    Code:
    Ext.define('Ext.util.Observable', {
        ...
        removeManagedListener : function(item, ename, fn, scope) {
            var me = this,
                ...,
                hasOwn = Object.prototype.hasOwnProperty; // <-- added
    
    
            if (typeof ename !== 'string') {
                options = ename;
                for (ename in options) {
                    // if (options.hasOwnProperty(ename)) {
                    if (hasOwn.call(options, ename)) {     
                        config = options[ename];
                        if (!me.eventOptionsRe.test(ename)) {
                            me.removeManagedListener(item, ename, config.fn || config, config.scope || options.scope);
                        }
                    }
                }
            }
            ...
        },
    ***Edit
    Performance improvement is minor, but it still might be worth it because it's a simple change.

    http://jsperf.com/hasownproperty-caching
    Last edited by LesJ; 8 Oct 2012 at 2:33 PM. Reason: Add test link

Thread Participants: 1