MyNewClass = function(arg1, arg2, etc) { // explicitly call the superclass constructor MyNewClass.superclass.constructor.call(this, arg1, arg2, etc); }; Ext.extend(MyNewClass, SomeBaseClass, { theDocument: Ext.get(document), myNewFn1: function() { // etc. }, myNewFn2: function() { // etc. } });
The following example is a real world extension to Ext to allow a resizable, draggable element to be constrained by a set of X, Y values that specify how far the object can be dragged in the horizontal and/or vertical planes.
// create constructor for new class Ext.ResizableConstrained = function(el, config){ Ext.ResizableConstrained.superclass.constructor.call(this, el, config); }; // extend the base class Ext.extend(Ext.ResizableConstrained, Ext.Resizable, { setXConstraint : function(left, right){ // Obtain a reference to parent dd property and setXConstraint this.dd.setXConstraint(left, right); }, setYConstraint : function(up, down){ // Obtain a reference to parent dd property and setYConstraint this.dd.setYConstraint(up, down); } }); // create an instance of the new class var myResizable = new Ext.ResizableConstrained('resize-el', { width: 200, height: 75, minWidth:100, minHeight:50, maxHeight:150, draggable:true }); // invoke the new methods myResizable.setYConstraint(0,300); myResizable.setXConstraint(0,300);
In English terms, you could read the above code generally as the following: "Ext.ResizableConstrained extends Ext.Resizable, and implements these methods..."
If you need to override a method but call the same method of the superclass you can do this as below:
MyClass = Ext.extend(Ext.SomeClass, { someFunction : function(arg1, arg2){ // custom code // call base class MyClass.superclass.someFunction.call(this, arg1, arg2); // custom code } );
Don't forget to pass this or it won't run in your object context.