/** * Extends one class to create a subclass and optionally overrides members with the passed literal. This method * also adds the function "override()" to the subclass that can be used to override members of the class. * For example, to create a subclass of Ext GridPanel: * MyGridPanel = Ext.extend(Ext.grid.GridPanel, { constructor: function(config) {
// Create configuration for this Grid. var store = new Ext.data.Store({...}); var colModel = new Ext.grid.ColumnModel({...});
// Create a new config object containing our computed properties // *plus* whatever was in the config parameter. config = Ext.apply({ store: store, colModel: colModel }, config);
MyGridPanel.superclass.constructor.call(this, config);
// Your postprocessing here },
yourMethod: function() { // etc. } });
* * This function also supports a 3-argument call in which the subclass's constructor is * passed as an argument. In this form, the parameters are as follows: * * subclass : Function The subclass constructor. * superclass : Function The constructor of class being extended * overrides : Object A literal with members which are copied into the subclass's * prototype, and are therefore shared among all instances of the new class. *
* * @param {Function} superclass The constructor of class being extended. * @param {Object} overrides A literal with members which are copied into the subclass's * prototype, and are therefore shared between all instances of the new class. * This may contain a special member named constructor. This is used * to define the constructor of the new class, and is returned. If this property is * not specified, a constructor is generated and returned which just calls the * superclass's constructor passing on its parameters. * It is essential that you call the superclass constructor in any provided constructor. See example code. * @return {Function} The subclass constructor from the overrides parameter, or a generated one if not provided. */ 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(Ext.isObject(sp)){ 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; Ext.override(sb, overrides); sb.extend = function(o){return Ext.extend(sb, o);}; return sb; }; }(),
|