someFunction.bind(this) does not statically bind the existing pointer to the
someFunction reference... it returns a new function which has the binding
made.

thus, change:

func.test.bind(this);


to:

func.test = func.test.bind(this);


OR... remove the extra line altogether and bind inline...

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



Ryan Gahl
CEO
Nth Penguin, LLC
http://www.nthpenguin.com
--
Inquire: 1-920-574-2218
Blog: http://www.someElement.com
LinkedIn Profile: http://www.linkedin.com/in/ryangahl


On Thu, Apr 9, 2009 at 2:36 PM, kstubs <kst...@gmail.com> 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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to