Jean-Baptiste BRIAUD -- Novlog schrieb:
> Hi again,
>
> I got a javascript question, basically, I'm trying to do like
> listener : I'm passing a function as a parameter :
>
JavaScript binds "this" to the object the function was called with. e.g.
in "button.foo()" this is set to "button". If you don't call the method
from an object, "this" is bound to the global object:
var foo = button.foo;
foo(); // this points to window
You can explicitly set the object, which should be bound to "this" by
using "call":
foo.call(button, ...); // this points to button
foo.apply(button, [...]); // this points to button
The first parameter is the object pointing to "this", all other
parameters are the normal arguments passed to the function. "apply" does
not use variable arbuments but expects the argument list in an array as
second parameter.
If you want to bind "this" for a specific method you can use qooxdoo's
bind method:
boundFoo = qx.lang.Function.bind(button.foo, button);
boundFoo(); // this points always to button
This binding is done by creating a closure.
bind = function(func, context)
return function() {
return func.apply(context, arguments);
}
}
Best Fabian
> myF("a", "b", function() { blabla });
>
> Then, in myF :
>
> myF : function(param1, param2, whatToDo) {
> // some code before
> whatToDo();
> // some code after
> }
>
> The problem : I'm using this inside blabla, for example :
> this.debug("blabla");
> Unfortunatly, this is not defined and the function passed to myF do
> not have parameter.
>
> I did try to force it like that but it didn't worked :
>
> myF : function(param1, param2, whatToDo) {
> // some code before
> whatToDo(this);
> // some code after
> }
>
> Note : all that code is inside the same class, so it make sense to
> share that this, exactly like the qooXdoo wel designed listener.
>
> I did try to start digging the qooXdoo sources, I convinced there is a
> lot to learn there, but that still too hard for now, I got lost in the
> qx.event.Manager :-)
>
> Any js guru there ?
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
>
--
Fabian Jakobs
JavaScript Framework Developer
1&1 Internet AG
Brauerstraße 48
76135 Karlsruhe
Amtsgericht Montabaur HRB 6484
Vorstand: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas
Gottschlich, Matthias Greve, Robert Hoffmann, Markus Huhn, Oliver Mauss, Achim
Weiss
Aufsichtsratsvorsitzender: Michael Scheeren
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel