1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default Calling the original function when using Ext.override

    Calling the original function when using Ext.override


    Based on this snippet:

    Code:
    Ext.override(Ext.form.BaseField, 
    {    
        setValue: function(value) 
        { 
            //Call the original                    
        },
    });
    What I want to do is redefine a function for everyone in BaseField without subclassing it. However, I still want it to do the original functionality without creating a recursive loop, obviously.

    I am new to the whole Ext.override concept. I would hate to subclass in this particular case and would love to use the Ext.override feature. I just want to add functionality and not take it away, and I don't even want to think about (*shutters*) copying the source code from the original implementation.

    Thanks!
    Last edited by wizkid; 24 Mar 2011 at 5:12 PM. Reason: Clarity

  2. #2
    Sencha User laurentParis's Avatar
    Join Date
    Aug 2010
    Location
    paris
    Posts
    246
    Vote Rating
    2
    laurentParis is on a distinguished road

      0  

    Default


    Try
    PHP Code:
    Ext.override(Ext.form.BaseField, {
        
    setValueOriginalExt.form.BaseField.prototype.setValue,
        
    setValue: function(value) {
            
    //Call the original
            
    this.setValueOriginal(value);
        }
    }); 
    Work with Ext3.x but not tested with Ext4

  3. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    750
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The new ExtJS4 way take from the source comments, notice the red line:

    Code:
    Ext.define('My.Cat', {
    	constructor: function() {
    		alert("I'm a cat!");
    		
    		return this;
    	}
    });
    My.Cat.override({
    	constructor: function() {
    		alert("I'm going to be a cat!");
    		
    		var instance = this.callOverridden();
    		
    		alert("Meeeeoooowwww");
    		
    		return instance;
    	}
    });
    This is also in the Core library.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Thanks it works like a treat!

    I won't pretend to understand the difference between:

    Ext.form.BaseField.override(

    and

    Ext.override(Ext.form.BaseField

    The first one worked. The 2nd one threw an exception about not being the owner and acting like the method was public rather than protected or something like that.

    I don't know what the difference is, they look the same to me! Anybody care to explain?

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,114
    Vote Rating
    507
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    The second one has been deprecated, use Foo.override.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Good to know. Maybe this is a bug then when I do:

    Code:
    Ext.data.validations.override(
    {
    
    });
    I get this error "Ext.data.validations.override is not a function"

    It works for other classes...

    Is this because it's singleton? The deprecated way sort of works, but if I add a function to the validations it balks at me when I try and use it.

    I am trying to add a new validation rule (one that does some fancy remote calls). Maybe there is a better way?

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Never mind yeah it's a singleton, so I thought about that for a while.... Singletons are not classes (duh) but rather an instance...

    So yeah I need to do something like this:

    Code:
    Ext.data.validations.remote = function(config, value)
        {
    
        }; //Where .remote is my new function
    I suppose that makes sense.

Similar Threads

  1. Calling C# function in Extjs
    By thomsonzh in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 18 Mar 2011, 2:00 PM
  2. calling function
    By emmas in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 3 Feb 2010, 10:16 AM
  3. [RESOLVED][2.2.1] Calling defined function throws a "is not a function" error
    By sam_mooball in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 19 Apr 2009, 11:08 PM
  4. Override, but calling original code
    By wuschba in forum Ext 2.x: Help & Discussion
    Replies: 15
    Last Post: 28 Oct 2008, 6:31 AM
  5. xtemplate and calling function
    By mnask in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 17 Mar 2008, 8:17 AM

Thread Participants: 3

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar