Results 1 to 3 of 3

Thread: Extending Ext classes and adding private variables and functions...

  1. #1
    Sencha User wolverine4277's Avatar
    Join Date
    Mar 2007
    Location
    Necochea, Buenos Aires, Argentina
    Posts
    61

    Default Extending Ext classes and adding private variables and functions...

    I have reading many post and also the learn section and i can't figure out how add private variables and private functions when i subclass some Ext class... i search in Internet for closures and all that i try don't work as i expected...
    Supossing that this is my class, i want to add some private variable (say privateVariable1) and some private function (say privateFunction1), anybody can give me a hand? Thanks.

    Code:
    MyClass = function(...) {
    
    	...
    	MyClass.superclass.constructor.call(this, ...);
    	...
    };
     
    Ext.extend(MyClass, Ext.SomeClass, {
    
    	publicVariable1: initialValue1,
    	publicVariable2: initialValue2,
    	...
    	publicVariableM: initialValueM,
    	publicFunction1: function(...) {...},
    	publicFunction2: function(...) {...},
    	...
    	publicFunctionN: function(...) {...}
    });

  2. #2
    Sencha User wolverine4277's Avatar
    Join Date
    Mar 2007
    Location
    Necochea, Buenos Aires, Argentina
    Posts
    61

    Default

    Can be...
    Code:
    MyClass = function(...) {
    
    	var privateVariable1;
    	var privateFunction1 = function() {...};
    	...
    	MyClass.superclass.constructor.call(this, ...);
    	...
    };
     
    Ext.extend(MyClass, Ext.SomeClass, {
    
    	publicVariable1: initialValue1,
    	publicVariable2: initialValue2,
    	...
    	publicVariableM: initialValueM,
    	publicFunction1: function(...) {...},
    	publicFunction2: function(...) {...},
    	...
    	publicFunctionN: function(...) {...}
    });
    the solution???

  3. #3
    Ext User matjaz's Avatar
    Join Date
    Apr 2007
    Location
    Slovenia
    Posts
    126

    Default

    Could be.. but with a major drawback. You can't access private members from public ones.

    There is one solution, but it has also drawbacks:
    Code:
    function MyClass()
    {
        var private = "x";
        this.public = function()
        {
             alert(private);
        }
    }
    As I said it has one major drawback. Every time you create new MyClass public member is created, so if you have 10 MyClasses, you'll have 10 different (with same functionality) functions.

    So use syntax as Ext and make clear (with comments) what's public and what isn't.
    Regards,
    M.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •