Could you please tell how to add a new method to Ext Core:
Ext.get('id').myMethod();
It doesn’t work:
Ext.extend(Ext.Element, {
myMethod: function() {
this.on('click', function() {
alert(this);
});
}
});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(Assuming you are using ExtJS 3)
No, that’s not the right way. We use
extendwhen we need to extend a Class and create our own class.Then if you would like to add additional functionalities or override some of the core methods, use
Ext.override. This action is permanent and destructive since you can override any defined methods. We useoverridewhen we want to apply personal fixes or global changes (like overridingExt.form.Fieldso to provide global, usable and crossfieldsfunctionalities).For your case, it seems like you want to apply this method to all the elements you have captured from
Ext.get. You will just need to overrideExt.Element.An working example is given here: jsfiddle.
Note that
Ext.getis giving youExt.Elementon a successful call. If you would like to create a customizedExt.Element, be sure to modifyExt.getso it will return your own customizedExt.Element, or provides your own customized function to get elements.Cheers!