Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    576
    Answers
    4
    Vote Rating
    9
    Dumas will become famous soon enough

      0  

    Default Answered: Add a static method to an existing class

    Answered: Add a static method to an existing class


    Hello,

    I want to add a static method to an existing class. I tried with the code below, but is doesn't seem to have an effect.

    When I use the code without the statics property the method is initialized at Ext.Class.prototype.unregisterPreprocessor, but the it doesn't work to set it as static method under
    Ext.Class.unregisterPreprocessor.

    Code:
    /**
     * Add a unregisterPreprocessor method to the {@class Ext.Class}.
     */
     Ext.define('Bancha.loader.override.Class', {
        override: 'Ext.Class',
        statics: {
            /**
             * @private
             * @static
             * Unregister a preprocessor
             * 
             * @param {String} name The pre-processor's name.
             * @return {void}
             */
            unregisterPreprocessor: function(name) {
                // remove the processor
                delete this.getPreprocessors()[name];
                var preprocessors = this.getDefaultPreprocessors(),
                    position;
    
    
                // also remove from the stack (may be multipl times)
                while((position = preprocessors.indexOf(name)) !== -1) {
                    preprocessors = Ext.Array.splice(preprocessors, position, 1);
                }
    
    
                this.setDefaultPreprocessors(preprocessors);
            }
        }
    });
    What do I need to adopt?

  2. The reason why you can't use Ext.define to override Ext.Class is because Ext.Class isn't defined using Ext.define. However, you can use Ext.define in another way so you still get class loading and such:

    Code:
    Ext.define('Override.Class', {
    }, function() {
        Override.Class = null;
    
        Ext.Class.foobar = function() {
            console.log('foobar');
        };
    });
    You could make this more elegant but now you can execute Ext.Class.foobar().

    Just for coverage, you can use Ext.define to override a class to add statics. Here is a quick test I made:

    Code:
    Ext.define('MyClass', {
        statics : {
            foo : function() {
                console.log('foo');
            }
        }
    });
    
    Ext.define('Override.MyClass', {
        override : 'MyClass',
    
        statics : {
            bar : function() {
                console.log('bar');
            }
        }
    });
    
    MyClass.foo();
    
    MyClass.bar();

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    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 reason why you can't use Ext.define to override Ext.Class is because Ext.Class isn't defined using Ext.define. However, you can use Ext.define in another way so you still get class loading and such:

    Code:
    Ext.define('Override.Class', {
    }, function() {
        Override.Class = null;
    
        Ext.Class.foobar = function() {
            console.log('foobar');
        };
    });
    You could make this more elegant but now you can execute Ext.Class.foobar().

    Just for coverage, you can use Ext.define to override a class to add statics. Here is a quick test I made:

    Code:
    Ext.define('MyClass', {
        statics : {
            foo : function() {
                console.log('foo');
            }
        }
    });
    
    Ext.define('Override.MyClass', {
        override : 'MyClass',
    
        statics : {
            bar : function() {
                console.log('bar');
            }
        }
    });
    
    MyClass.foo();
    
    MyClass.bar();
    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. #3
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    576
    Answers
    4
    Vote Rating
    9
    Dumas will become famous soon enough

      0  

    Default


    Hello Mitchell,

    thanks for the answer. I already solved the problem by doing:
    Code:
    Ext.define('Bancha.Loader', {
         requires: 'Ext.Loader'
    }, function() {
        Bancha.Loader = {};
    
    
        // Ext.Loader is a singleton,
        // so we need to directly apply the overrides
        Ext.apply(Ext.Loader, {
            ...
        });
    });
    Best regards,
    Roland

Thread Participants: 1