Hi Michael,

if you pass function pointers, you will loos the context (as you do in the
listener of the button). JavaScript offers a way of setting the context my
using the call method of functions:
    guiMethod :function(method) {
      method.call(this.server, this);
    },
The first argument is the context and all following parameter will be
available as parameter in the called method.
Best,
Martin


Michael Greifeneder wrote:
> 
> Hello,
> 
> I have a strange problem, that's probably easily solved with a little
> JavaScript/Qooxdoo knowledge.
> Clicking on the button in the example code below causes this error:
> 
> this.internMethod is not a function
> [Break on this error] this.internMethod();\n
> 
> Classes test.Application and test.Server are in 2 different files.
> Maybe it's because of lack of JavaScript knowledge, but passing a
> function to another function should work in JavaScript that way? Can
> the closure cause the problem?
> Debugging shows that in class Server the reference "this" points to the
> window?
> Thanks for any hint.
> Mike
> 
> qx.Class.define("test.Application",
> {
>   extend : qx.application.Standalone,
>   members :
>   {
>     main : function()
>     {
>       this.base(arguments);
>       var button1 = new qx.ui.form.Button("First Button",
> "test/test.png");
>       var doc = this.getRoot();
>       doc.add(button1, {left: 100, top: 50});
>       button1.addListener("execute", function(e) {
>         this.guiMethod(this.server.serverMethod);
>       }, this);
>     },
> 
>     guiMethod :function(method) {
>       method(this);
>     },
> 
>     server: new test.Server()
>   }
> });
> 
> qx.Class.define("test.Server",
> {
>   extend: qx.core.Object,
> 
>   construct : function() {
>     this.base(arguments);
>   },
> 
>   members :
>   {
>     internMethod : function() {
>       alert("Works!");
>     },
> 
>     serverMethod : function() {
>       this.internMethod();
>     }
>   }
> });
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day 
> trial. Simplify your report design, integration and deployment - and focus
> on 
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/this-reference-tp4059763p4063284.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to