Hi,

> When I change the line into "new PeriodicalExecuter
> (myobject.unknownMethod(), 3);", firebug at once states correctly that
> this function doesn't exist, which is right.

And if it did exist, it would execute once, immediately, and the
PeriodicalExecuter would fail three seconds later.  This line of code:

new PeriodicalExecuter(obj.method(), 3);

...like any other function call runs obj.method _immediately_ and
passes the return value of the method into the PeriodicalExecuter
constructor.  Unless the method returns a function reference, that's
not going to work.

You probably want to do this:

new PeriodicalExecuter(obj.method.bind(obj), 3);

Note that we are *not* calling method here; we're calling bind and
telling it to return a function that, when called, will call
obj.method.

If you're not using an object method, just a function, you don't need
bind:

new PeriodicalExecuter(someFunction, 3);

Note, again, that we are not *calling* someFunction there (there are
no parens after it), we're just passing a reference to it into the
constructor.

[1] http://prototypejs.org/api/periodicalExecuter
[2] http://prototypejs.org/api/function/bind

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 7, 1:30 am, Schweitzer <lul...@gmx.de> wrote:
> Hi there!
>
> Got an error with Prototypes PeriodicalExecuter() (Version 1.6.0.3):
> When I use the "verified" (http://www.prototypejs.org/api/
> periodicalExecuter) "new PeriodicalExecuter(myobject.testMethod(),
> 3);", everything seems fine (no error in Firebug etc) but after 3
> Seconds an error "this.callback is not a function [...]/prototype.js
> Line 308" appears. testMethod was not started.
>
> The line "new PeriodicalExecuter(function() { alert("test"); }, 3);"
> works when written instead.
>
> When I change the line into "new PeriodicalExecuter
> (myobject.unknownMethod(), 3);", firebug at once states correctly that
> this function doesn't exist, which is right.
>
> Now I wonder about why this error appears. As you may imagine,
> testMethod() is part of an Object, but the error appears outside as
> inside the initialize()-function of the "Class" created by Class.create
> (). Even outside the "class". The used testMethod() seems to exist
> nonetheless.
>
> I would like to read any hint or maybe solution to this problem,
> please feel free to ask for more information, too.
>
> Schweitzer
--~--~---------~--~----~------------~-------~--~----~
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