Thanks Alexey for your detailed explanation of the key word this.

@ Keve

Sure you are able to declare local variables with function in qooxdoo class, 
however. To be able to access parent scope you are able to do like this: (just 
declare a local variable in the function which includes your function) 

var that = this;
var myDebug = function(p_myString) {
        that.debug(p_myString);
        return true;
};

Or if you want to change the function scope / context totally: (use the bind 
function, qooxdoo provides an polyfill for bind to support older browsers)

var myDebug = function(p_myString) {
        this.debug(p_myString);
        return true;
}.bind(this);

But my advice to you would be to declare any function in the members section of 
qooxdoo classes. If you do so the scope is "normally" set to the class 
instance, expect calling member functions through a callback mechanism, in that 
case you have to set the scope manually, e.g. this.addListener("appear", 
this._onAppear, this);

But you could re structure your code in such a way:
...
members :
{
  main: function() {
        this.myDebug("Indirect debug via myDebug().");
  },

  myDebug : function(p_myString) {
        this.debug(p_myString);
        return true;
  }
}


...


Hope could help a bit

Gruß
Mustafa Sak

Applications & Integration

1&1 Internet AG
Ernst-Frey-Straße 10
DE-76135 Karlsruhe

-----Ursprüngliche Nachricht-----
Von: alexey.zakharenkov [mailto:a-z...@yandex.ru] 
Gesendet: Donnerstag, 27. Februar 2014 07:36
An: qooxdoo-devel@lists.sourceforge.net
Betreff: Re: [qooxdoo-devel] Newbie question, calling this.debug() from my 
function.

"this" keyword has different meaning in different points of the script: they 
say it "depends on context". this.debug() will work only where "this" refers to 
an instance of qx.core.Object or derived class, or any class that includes 
qx.core.MLogging mixin.
Explore what is "this" (by calling alert(this), e.g.) at different lines of 
your program, and you'll see it's not the same.
For the debug() function to work anywhere in the script, use static method
qx.log.Logger.debug()

--
Regards,
Alexey


Keve Nagy wrote
> Good Evening Everyone!
> I believe this is a newbie question.
> I very much like using the this.debug() call during development. But 
> when I try to call it from any function I define inside my qx 
> application code, it doesn't work. It resolves as "undefined".
> Example:
> 
>       this.debug("Debug text directly using this.debug()");
>       //
>       var myAlert = function(p_myString) {
>               alert(p_myString);
>               return true;
>       }
>       //
>       myAlert("Indirectly calling alert() from myAlert().");
>       //
>       var myDebug = function(p_myString) {
>               this.debug(p_myString);
>               return true;
>       }
>       //
>       myDebug("Indirect debug via myDebug().");
> 
> The direct call on line #1 works, debug message shows up in the console.
> myAlert gets defined fine, calling myAlert works fine and shows the 
> pop-up window.
> Script fails to load during the definition of myDebug, complaining 
> that this.debug is "undefined".
> I also tried replacing this.debug() with 
> myapplicationnamehere.Application.debug(), also fails.
> 
> How do I call the debug() function from inside my own function?
> Or -if that is what I do wrong- how do I define my own function 
> differently to be able to call this.debug() from inside of it?
> 
> Regards,
> Keve Nagy * Debrecen * Hungary
> 
> 
> ----------------------------------------------------------------------
> -------- Flow-based real-time traffic analytics software. Cisco 
> certified tool.
> Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer 
> Customize your own dashboards, set traffic alerts and generate reports.
> Network behavioral analysis & security monitoring. All-in-one tool.
> http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.
> clktrk _______________________________________________
> qooxdoo-devel mailing list

> qooxdoo-devel@.sourceforge

> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel





--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Newbie-question-calling-this-debug-from-my-function-tp7585391p7585392.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize 
your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to