On 9/27/06, DJK <[EMAIL PROTECTED]> wrote:
>
> Can someone explain why the following code does not work? The function
> f prints "this" as an "object" but the function g will print it as the
> current window. I thought the call to bindMethods would fix the this
> pointer???
>
> function c() {
>
> this.f = f;
> function f() {
> log('f', this); // print [object Object]
> g();
> }
> function g() {
> log('g', this); // prints [object Window]
> }
> bindMethods(this);
> }
> inst = new c();
>
> connect(currentWindow(), 'onload', inst, inst.f);
No, that's not how it works. You actually can't do what you think
should happen in JavaScript at all.
bindMethods binds methods. g is not a method, it's a function. It has
nothing at all to do with the object other than the fact that it's
defined inside the constructor.
-bob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---