Ext.apply(Ext, function(){
var E = Ext, idSeed = 0;
return {
emptyFn : function(){},//空函数
value : function(v, defaultValue, allowBlank){
return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
},
escapeRe : function(s) {//对特殊字符转义
return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
},
sequence : function(o, name, fn, scope){//创建队列函数
o[name] = o[name].createSequence(fn, scope);
},
addBehaviors : function(o){//添加时间行为
if(!Ext.isReady){
Ext.onReady(function(){
Ext.addBehaviors(o);
});
} else {
var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
parts,
b,
s;
for (b in o) {
if ((parts = b.split('@'))[1]) { // for Object prototype breakers
s = parts[0];
if(!cache[s]){
cache[s] = Ext.select(s);
}
cache[s].on(parts[1], o[b]);
}
}
cache = null;
}
},
combine : function(){//数据组合,返回组合后的数据
//把所有参数拼到一个数组中返回 Ext.combine(['a','b'],'c') 返回['a','b','c']
var as = arguments, l = as.length, r = [];
for(var i = 0; i < l; i++){
var a = as[i];
if(Ext.isArray(a)){
r = r.concat(a);
}else if(a.length !== undefined && !a.substr){
r = r.concat(Array.prototype.slice.call(a, 0));
}else{
r.push(a);
}
}
return r;
},
copyTo : function(dest, source, names){//把某对象的属性复制给目标对象names为属性名,可以是数组,字符串
* @param {Object} The destination object.
* @param {Object} The source object.
* @param {Array/String} Either an Array of property names, or a comma-delimited list
* of property names to copy.
* @return {Object} The modified object.
if(typeof names == 'string'){
names = names.split(/[,;\s]/);
}
Ext.each(names, function(name){
if(source.hasOwnProperty(name)){
dest[name] = source[name];
}
}, this);
return dest;
},
destroy : function(){//清除对象属性,DOM节点
Ext.each(arguments, function(arg){
if(arg){
if(Ext.isArray(arg)){
this.destroy.apply(this, arg);
}else if(Ext.isFunction(arg.destroy)){
arg.destroy();
}else if(arg.dom){
arg.remove();
}
}
}, this);
},
destroyMembers : function(o, arg1, arg2, etc){
for(var i = 1, a = arguments, len = a.length; i < len; i++) {
Ext.destroy(o[a[i]]);
delete o[a[i]];
}
},
clean : function(arr){
var ret = [];
Ext.each(arr, function(v){
if(!!v){
ret.push(v);
}
});
return ret;
},
unique : function(arr){
var ret = [],
collect = {};
Ext.each(arr, function(v) {
if(!collect[v]){
ret.push(v);
}
collect[v] = true;
});
return ret;
},
getCmp : function(id){//获取组建对象
return Ext.ComponentMgr.get(id);
},
type : function(o){
if(o === undefined || o === null){
return false;
}
if(o.htmlElement){
return 'element';
}
var t = typeof o;
if(t == 'object' && o.nodeName) {
switch(o.nodeType) {
case 1: return 'element';
case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
}
}
if(t == 'object' || t == 'function') {
switch(o.constructor) {
case Array: return 'array';
case RegExp: return 'regexp';
case Date: return 'date';
}
if(typeof o.length == 'number' && typeof o.item == 'function') {
return 'nodelist';
}
}
return t;
},
intercept : function(o, name, fn, scope){
o[name] = o[name].createInterceptor(fn, scope);
},
// internal
callback : function(cb, scope, args, delay){
if(Ext.isFunction(cb)){
if(delay){
cb.defer(delay, scope, args || []);
}else{
cb.apply(scope, args || []);
}
}
}
}
})
extjs源码分析-016(Ext....)
最新推荐文章于 2016-04-13 09:49:25 发布