`
编程足球
  • 浏览: 251424 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

Ext3.4源码之Ext.apply()和 Ext.applyif()

    博客分类:
  • Ext
 
阅读更多
1. 查看ext-base.js中的源码可知:

Ext.apply()源码
/**
 * Copies all the properties of config to obj.
 * @param {Object} obj The receiver of the properties(目标)
 * @param {Object} config The source of the properties(数据源)
 * @param {Object} defaults A different object that will also be applied for default values(目标默认值)
 * @return {Object} returns obj
 * @member Ext apply
 */
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;
};


上看面的源码就知道其实Ext.apply()就是一个简单的属性复制功能


Ext.applyIf()源码
applyIf : function(o, c){
            if(o){
                for(var p in c){
                    // 不存在才会去覆盖,是指未定义,而不同于null
                    if(!Ext.isDefined(o[p])){
                        o[p] = c[p];
                    }
                }
            }
            return o;
        }



// 未定义,而不是单纯的null
isDefined : function(v){
    return typeof v !== 'undefined';
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics