OK, working good! Now onto the next question, that last was just a
lead up.
So I am setting a timer, waiting 300/1 second for user to seize
typing. When user is completed typing, the method calls itself
passing the original input element, original event, and a 3rd
parameter, "useractive" false.
Previously, this.Find() was not defined, now that I am binding
properly it is! Now, the problem is the event value is not passing
properly. The 1st line in the Find function is:
var keycode = event.keyCode
keyCode is defined the first time in, but not defined after invoked
with the timer. The timer code looks like this:
var func = function() { this.Find(input, event, false); };
func = func.bind(this);
this.timer = setTimeout(func, 300);
The method definition for Find looks like this:
Find: function(input, event, useractive) {
Find is invoked by keypress like this:
onkeyup="_mf.Find(this, event, true);"
So any ideas what is happening to the event after the timeout is set?
do I need to pass the event in as a param of the function() statement?
Thanks!
On Apr 9, 12:49 pm, Ryan Gahl <[email protected]> wrote:
> 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, LLChttp://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 <[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
-~----------~----~----~----~------~----~------~--~---