Results 1 to 3 of 3

Thread: "Public" and "Private" Fields

  1. #1

    Default "Public" and "Private" Fields

    I am creating an extension of panel with a series of configurations, and I want this subclass to have public and private methods. Here is a snippet:

    MyWidget.MainPanel = function(config) {
        var defaultMargins = '5 5 5 5';
        var gridStore = new{
            url : 'data/myWidget.xml',
            reader : new{id : 'Id',record : 'Record'}, [ 'Name', 'Id' ])
         var checkboxSelectionModel = new Ext.grid.CheckboxSelectionModel();
         function launchWindow()
        Ext.apply(mainPanelConfig, config);
        Ext.apply(this, mainPanelConfig);
    var myWidget = Ext.extend(MyWidget.MainPanel,Ext.Panel);
    My understanding is that the properties and methods defined as above inside MyWidget.MainPanel are all "private." I want to expose properties and methods as public so that a caller or a JSUnit test can call or access MyWidget.MainPanel.gridStore.

    Any insight into this is much appreciated.


  2. #2
    Ext User
    Join Date
    Nov 2007
    Centreville, VA


    The short answer is make an assignment like this.gridStore = gridStore in the constructor. Any properties you set on this will be public. But if you are going to make these properties public, why bother making them private to begin with?

  3. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Sydney, Australia


    It's the same issue with any other language, if you want to unit test private members you have to do something out of the ordinary to access them. That being said, making members fully private takes a little effort in JS, Ext, for example just marks private members with a comment, as opposed to enforcing their access level.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Posting Permissions

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