/**
* Extends one class with another class and optionally overrides members with the passed literal. This class
* also adds the function "override()" to the class that can be used to override
* members on an instance.
* @param {Object} subclass The class inheriting the functionality
* @param {Object} superclass The class being extended
* @param {Object} overrides (optional) A literal with members
* @method extend
*/
extend : function(){
// inline overrides
var io = function(o){
for(var m in o){
this[m] = o[m];
}
};
return function(sb, sp, overrides){
if(typeof sp == 'object'){
overrides = sp;
sp = sb;
sb = 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 == Object.prototype.constructor){
spp.constructor=sp;
}
sb.override = function(o){
Ext.override(sb, o);
};
sbp.override = io;
sbp.__extcls = sb;
Ext.override(sb, overrides);
return sb;
};
}(),
* Extends one class with another class and optionally overrides members with the passed literal. This class
* also adds the function "override()" to the class that can be used to override
* members on an instance.
* @param {Object} subclass The class inheriting the functionality
* @param {Object} superclass The class being extended
* @param {Object} overrides (optional) A literal with members
* @method extend
*/
extend : function(){
// inline overrides
var io = function(o){
for(var m in o){
this[m] = o[m];
}
};
return function(sb, sp, overrides){
if(typeof sp == 'object'){
overrides = sp;
sp = sb;
sb = 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 == Object.prototype.constructor){
spp.constructor=sp;
}
sb.override = function(o){
Ext.override(sb, o);
};
sbp.override = io;
sbp.__extcls = sb;
Ext.override(sb, overrides);
return sb;
};
}(),
var io = function(o){
for(var m in o){
this[m] = o[m];
}
};
这里就是简单的对象复制,将o中所有的属性全部copy到自身,完成了对象复制
而这里sb = function(){sp.apply(this, arguments);
用apply来完成对象冒充(用于构造函数)
F.prototype = spp;
sbp = sb.prototype = new F();
这里是原型链,将方法继承到自身,同时可通过判断是否覆盖
// inline overrides
var io = function(o){ //函数中的变量 用于对象的扩展
for(var m in o){
this[m] = o[m]; //把o对象中的所有属性都复制给this对象
}
};
return function(sb, sp, overrides){ //返回一个用于返回对象的函数
//以下就是一个扩展属性的东西,解释起来太多偷懒了
if(typeof sp == 'object '){ //如果sp 是对象
overrides = sp; //传递
sp = sb; //传递
sb = function(){sp.apply(this, arguments);}; // sb 该是基对象
}
var F = function(){}, sbp, spp = sp.prototype; //spp是sp的原型
F.prototype = spp; //F的原型就是sp的原型
sbp = sb.prototype = new F(); // sbp 该是 sb的 原型
sbp.constructor=sb; //sbp的构造函数 是sb constructor该是自己加上去的属性
sb.superclass=spp; //超类
if(spp.constructor == Object.prototype.constructor){
spp.constructor=sp;
}
sb.override = function(o){
Ext.override(sb, o); //重写覆盖
};
sbp.override = io;
sbp.__extcls = sb;
Ext.override(sb, overrides);//扩展
return sb;
};
}(),
sb.override = function(o){
Ext.override(sb, o);
}; 这个o 参数使怎么回事?换句话说如果调用了extend函数,执行了override函数,那么那个变量的值传入该函数呀!
!另外就sbp起什么作用呀