I am trying to do something exactly like this.
I suppose you are also trying to guarantee that a function's this always
refers to its original owner?
Anyway, have you tried

this func = (test:function(){return this.name;}}

instead of var func = ...

?


On Thu, Apr 9, 2009 at 3:36 PM, kstubs <[email protected]> wrote:

>
> I am trying to bind a function to it's class, so in the below example
> I am expecting a result of "X Class" when I call method test(),
> instead I'm receiving "undefined".  I am trying this with and without
> the bind method for the function.  What am I doing wrong?
>
> Karl..
>
> var x = Class.create({
> name: 'Class X',
> test: function()
> {
> var func = { test: function() { return this.name; } }
> func.test.bind(this);
> return func.test();
> },
>
> });
>
> var y = new x();
> y.test();
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to