Extjs 学习之路 2015/5/25

Ext.apply函数  把c(copy)对象的属性复制给o(object)  同名属性会覆盖目标对象上的属性

Ext.apply = function(o, c, defaults){
    // no "this" reference for friendly out of scope calls
    if(defaults){
        Ext.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];
        }
    }
    return o;
};

 

 1  1 (function(){
 2  2     var idSeed = 0,
 3  3         toString = Object.prototype.toString,
 4  4         ua = navigator.userAgent.toLowerCase(),
 5  5         check = function(r){
 6  6             return r.test(ua);
 7  7         },
 8  8         DOC = document,
 9  9         docMode = DOC.documentMode,
10 10         isStrict = DOC.compatMode == "CSS1Compat", //标准模式
11 11         isOpera = check(/opera/),
12 12         isChrome = check(/\bchrome\b/),
13 13         isWebKit = check(/webkit/),
14 14         isSafari = !isChrome && check(/safari/),
15 15         isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
16 16         isSafari3 = isSafari && check(/version\/3/),
17 17         isSafari4 = isSafari && check(/version\/4/),
18 18         isIE = !isOpera && check(/msie/),
19 19         isIE7 = isIE && (check(/msie 7/) || docMode == 7),
20 20         isIE8 = isIE && (check(/msie 8/) && docMode != 7),
21 21         isIE6 = isIE && !isIE7 && !isIE8,
22 22         isGecko = !isWebKit && check(/gecko/),
23 23         isGecko2 = isGecko && check(/rv:1\.8/),
24 24         isGecko3 = isGecko && check(/rv:1\.9/),
25 25         isBorderBox = isIE && !isStrict,
26 26         isWindows = check(/windows|win32/),
27 27         isMac = check(/macintosh|mac os x/),
28 28         isAir = check(/adobeair/),
29 29         isLinux = check(/linux/),
30 30         isSecure = /^https/i.test(window.location.protocol);
31 31 
32 32     // remove css image flicker
33 33     if(isIE6){
34 34         try{
35 35             DOC.execCommand("BackgroundImageCache", false, true);
36 36         }catch(e){}
37 37     }

 

Ext.applyIf

 applyIf : function(o, c){
            if(o){
                for(var p in c){
                    if(!Ext.isDefined(o[p])){
                        o[p] = c[p];
                    }
                }
            }
            return o;
        },
 1      /**
 2          * Generates unique ids. If the element already has an id, it is unchanged
 3          * @param {Mixed} el (optional) The element to generate an id for
 4          * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
 5          * @return {String} The generated Id.
 6          */
 7         id : function(el, prefix){
 8             el = Ext.getDom(el, true) || {};
 9             if (!el.id) {
10                 el.id = (prefix || "ext-gen") + (++idSeed);
11             }
12             return el.id;
13         },
 extend : function(){
            // inline overrides
            var io = function(o){
                for(var m in o){
                    this[m] = o[m];
                }
            };
            var oc = Object.prototype.constructor;

            return function(sb, sp, overrides){
                if(typeof sp == 'object'){
                    overrides = sp;
                    sp = sb;
                    sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
                }
                var F = function(){},
                    sbp,
                    spp = sp.prototype;

                F.prototype = spp;
                sbp = sb.prototype = new F();
                sbp.constructor=sb;
                sb.superclass=spp;
                if(spp.constructor == oc){
                    spp.constructor=sp;
                }
                sb.override = function(o){
                    Ext.override(sb, o);
                };
                sbp.superclass = sbp.supr = (function(){
                    return spp;
                });
                sbp.override = io;
                Ext.override(sb, overrides);
                sb.extend = function(o){return Ext.extend(sb, o);};
                return sb;
            };
        }(),

        /**
         * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
         * Usage:<pre><code>
Ext.override(MyClass, {
    newMethod1: function(){
        // etc.
    },
    newMethod2: function(foo){
        // etc.
    }
});
</code></pre>
         * @param {Object} origclass The class to override
         * @param {Object} overrides The list of functions to add to origClass.  This should be specified as an object literal
         * containing one or more methods.
         * @method override
         */
        override : function(origclass, overrides){
            if(overrides){
                var p = origclass.prototype;
                Ext.apply(p, overrides);
                if(Ext.isIE && overrides.hasOwnProperty('toString')){
                    p.toString = overrides.toString;
                }
            }
        },

 

posted on 2015-05-25 23:10  holy翟翟  阅读(62)  评论(0)    收藏  举报

导航