I have a general question about the context of callback functions:

I have, for example, in an arbitrary class a model which I want to modify
with different textboxes, for that I have defined a 

converter function because I want to deal with numbers instead of strings:


tf.bind("value", model, tar, {
                converter : function(value) {   return (parseFloat(value));     
}
        });



but now I want to handle language specific number conversion, therefore I
have a member function of a class which depends on a 

property of that object (mainUI.StringToNumber(value)), therefor I need a
this-reference in the converter, but there is no 'this' 

defined
        

tf.bind("value", model, tar, {
                converter : function(value) {   return 
this.mainUI.StringToNumber(value);
//ERROR: this not defined       }
        });
        
        
One solution might be to define a Javascript variable which holds the
object:


var tf = new qx.ui.form.TextField();
var objMainUI = this.mainUI;
tf.bind("value", model, tar, {
        converter : function(value) {
                return objMainUI.StringToNumber(value);
        }
});


But this solution is looking a little bit weird.
Is there a possibility to pass the this-reference to the callback function?





Another question is:
I have a button, in that execute listener I want to call a callback function
which is defined in another class, and in that callback-

function I want to use the this-reference of the same class, how can I do
that?
For example:



qx.Class.define("proj.Statics",
{
   extend: qx.core.Object,
   include : [qx.locale.MTranslation],

        
        statics :
        {
                        showConfirmationDialog: function(type, message, 
callback)
                        {
                                //......
                                var button = new qx.ui.form.Button();
                                
                                button.addListener("execute",  function(e) 
                                {
                                        callback();
                                }, this);
                                
                        }
        }
}
);


qx.Class.define("proj.MainUI",
{
        extend: qx.core.Object,

        members :
        {
                test : function(applicationRoot)
                {
                
upa.Statics.showConfirmationDialog(upa.Statics.CONFIRMATION_DIALOG_TYPE_INFO,
"Test" ,  function(e) 
                        {
                                //
-----------------------------------------------------???????????????????????????????
                                //here I want to use 'this' (Rererence of the 
object of 'proj.MainUI')
                        });
                }
        }
});






Are there any ideas how to achieve this?


Thank you very much!

Regards,

Hans Juergen











--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/General-question-about-callback-functions-and-the-context-of-them-tp7581129.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to