PDA

View Full Version : Ext.extend Extendido



vmacias1216
28 Sep 2010, 1:02 PM
Sobrescribí el método "Ext.extend" para que me permita simular métodos estáticos


Ext.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;

if (overrides.statics) {
Ext.apply(sb, overrides.statics);
delete overrides['statics'];
}

Ext.override(sb, overrides);

sb.extend = function(o){return Ext.extend(sb, o);};
return sb;
};
}();


Ejemplo:


Ext.ux.Clase = Ext.extend(Object, {
constructor: function(a, b, c) {
var Me = {
//Propiedades:
tA: a,
tB: b,
tC: c
};

Ext.apply(this, Me);
},
statics: {
Metodo: function(a) {
return new Ext.ux.Clase(a, a, a);
}
},

getTa: function() {

return this.tA;
},

getTb: function() {

return this.tB;
},

getTc: function() {

return this.tC;
}
});



Para este ejemplo yo puedo escribir:


var x = Ext.ux.Clase.Metodo(3);
alert(x.getTa());
alert(x.getTb());
alert(x.getTc());