Reputation: 652
I have a need to override native constructor of one of Extjs classes. If to be more exact Ext.ensible.cal.DragZone, it is from extensible calendar.
What I have tried, and what solutions I have found
Put desired code to original code, but I want to avoid original code modifications. All my changes I want to keep in one place
Ext.override - it doesn't work. native constructor is called anyway
Fully duplicate the code from original library, but with my changes. Ext.ensible.cal.DragZone = Ext.extend(Ext.dd.DragZone, {..... }); But this causes some other unexpected error, seems that not all functionality is called(some of fields of the class, seems not to be properly initialized). But if I just put this code, instead of original, everything works fine(but see #1)
Create my own Ext.ensible.cal.DragZone by extending the original. Problem of this method, is that I need to review all the code of library, and override and/or extend all other classes which uses this DragZone, to make them to use mine.
So can you advise me smth. The most correct solution for me seems to be just constructor overriding.
How I overriding:
Ext.override(Ext.ensible.cal.DragZone, {
constructor : function () {
...
}
});
But as I told, original constructor is called
Upvotes: 0
Views: 534
Reputation: 92274
Here's a hack you can try, remember that the class name is the constructor, there is actually no constructor property on the class that is generated
Ext.ensible.cal.DragZone = function () {
// This is not very nice, it'd be better if you didn't have to
// assume what the parent is, but since we're already hacking it...
Ext.dd.DragZone.apply(this, arguments) ;
// Your code here
}
Note that this is not the safe approach as I mentioned in my comment, but should work
I suggest you use approach 4 so that your modifications only apply to classes that choose to use it.
Upvotes: 1