ITeye博客

extjs源码分析-001(Ext.apply)

y1d2y3xyz · 2011-02-07 15:15 · Extjs · Web前端 · Markdown


/**
 * Copies all the properties of config to obj.
 * @param {Object} 继承的对象
 * @param {Object} 新的配置参数--这个值可以为空
 * @param {Object} 新的配置参数--这个值可以为空
 * @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;   
}; 
//执行过程是:将c的值和defaults的值拷贝给o,然后返回o对象
//使用方式:
var o = {};
var c = {name:'tom',showName:function(){alert(name);}};
var d = {age:23};
Ext.apply(o,c,d);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。