Hi, > ... But when the complexity of the actions increases, I > will attempt to consolidate logic in member functions which are called > from > the listeners...
You can do that without making them member functions, if you like. There's no reason you can't have named functions inside your constructor or your __initLayout method. Those named functions will have access to the variables (and parameters) of the function they're inside, even after that function terminates -- an idea which is probably a bit alien if (like me) you're from a C or Java background. E.g.: ================================= someSetupMethod : function() { var textfield; var checkbox; // Create text field textfield = new qx.ui.form.TextField; // (add to doc, etc.) // Create checkbox checkbox = new qx.ui.form.CheckBox("Enable text field"); checkbox.setChecked(true); // (add to doc, etc.) // Have checkbox toggle text field's "enabled" state via handleChangeChecked checkbox.addEventListener("changeChecked", handleChangeChecked); // The handleChangeChecked function function handleChangeValue() { // Enable the text field if checked (by inheriting), disable it if unchecked textfield.setEnabled(this.getChecked() ? "inherit" : false); }; // <== You want this semicolon: Declaring a function is a statement, // statements need terminators, don't trust JS's "terminator insertion" }, ================================= The handleChangeValue method's scope inherits the textfield (and checkbox) variables from someSetupMethod's scope, and keeps them after someSetupMethod terminates -- because they haven't gone out of scope. (This doesn't just happen with named functions, it happens with the anonymous ones you're already using, too, whether they reference the variable(s) or not. You can see how it's pretty easy to set up memory leaks in JavaScript if you're unwary.) Now, in the above, both the text field and the event handler for the checkbox are private -- no one can get at them from the outside. But in your original post, you wanted a public method that would access a private variable (the text field). You can do that, too: ================================= someSetupMethod : function() { var textfield; // Create text field textfield = new qx.ui.form.TextField; // (add to doc, etc.) // Create a public method to return the value this.getTextValue = function() { return textfield.getValue(); }; }, ================================= Now, users of your class can call getTextValue -- it's public -- but the textfield reference is private. At first this seems to conflict a bit with Qooxdoo's class declaration mechanism, because you're defining the public method inside a method rather than as a member in the data structure you pass into qx.Class.define. I don't think it's a problem, though I haven't tried it yet (too new to Qooxdoo). You could just define an empty method for qx.Class.define -- for instance, so you get to use Qooxdoo's excellent documentation automation -- and then you're just refining (okay, replacing) it later in someSetupMethod. E.g.: ================================= someSetupMethod : function() { var textfield; // Create text field textfield = new qx.ui.form.TextField; // (add to doc, etc.) // Create a public method to return the value this.getTextValue = function() { return textfield.getValue(); }; }, getTextValue: function() { // The implementation of this is defined in someSetupMethod }, ================================= I'd expect that to work because someSetupMethod will be called after qx.Class.define processes the data structure with the placeholder. If you have lots of temporary variables you use in your setup method, you'll want to be aware that they're preserved by any named or anonymous function you define in the setup method, whether they're referenced by those functions or not (because JavaScript is a dynamic language). There are syntactic ways around this, allowing you to only preserve the ones you want preserved. If you want to get into the depths of JavaScript's rather interesting (and powerful, and frightenting) scoping features, check out http://www.crockford.com. FWIW -- T.J. Crowder tj at crowder software dot com ----- Original Message ----- From: "mshillin" <[EMAIL PROTECTED]> To: <qooxdoo-devel@lists.sourceforge.net> Sent: Wednesday, October 03, 2007 2:16 PM Subject: Re: [qooxdoo-devel] Use of "this" to access class member variables/UI components > > It is not a problem to code like this - I just wanted to make sure I am > coding the correct way and there was not some "trick" to accessing UI > components in a layout. It is a bit of a hassle when I am refactoring. > > If I perform "simple actions" on UI components, the logic goes into event > listeners that are defined in-line. I don't make the UI components > members, > because I don't have to. But when the complexity of the actions increases, > I > will attempt to consolidate logic in member functions which are called > from > the listeners. When I do this, I have to go back and make the UI > components > class members so the member functions can "see" them. This means > pre-pending every UI component reference with "this." > > Maybe I am just used to programming in Java and not Javascript. > > > > -- > View this message in context: > http://www.nabble.com/Use-of-%22this%22-to-access-class-member-variables-UI-components-tf4561133.html#a13018774 > Sent from the qooxdoo-devel mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > qooxdoo-devel mailing list > qooxdoo-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel