I'm sorry, I made some typos. This is correct:
// where obj is obviously your object
var func = function() {
this.doSomething()
}.bind( obj );
window.setTimeout( func, 1000 );
Daan
On Thu, Dec 3, 2009 at 15:28, Daan Mortier <[email protected]> wrote:
> To pass a function to setTimeout that is binded to an object of choice, to
> something along these lines:
>
> // where obj is obviously your object
> var func = function() {
> this.doSomething()
> }.bind( this );
> window.setTimeout( func, 1000 );
>
>
> Function.prototype.bind is a function that's defined in the Prototype
> library. Hope this helps.
>
> Daan
>
> On Wed, Dec 2, 2009 at 15:25, fma <[email protected]> wrote:
>
>> Hi,
>>
>> I'm new to Prototype. I'm using it to write a little application for
>> our photoclub. Its goal is to allow users to upload photos, and then
>> vote for them.
>>
>> I display all the thumbs, and a double-click on a thumb opens the
>> photo in full-screen (in a div). As the photo can take time to load, I
>> use setTimeout() to delay the display. The code looks like:
>>
>> But it does not work. In the _show() method, the call to
>> this._flashNavButtons() leads to an error (this._flashNavButtons() is
>> not a function). I think I understand why: when called from the
>> timeout mecanism, 'this' no longer exists, or does not point anymore
>> on my object...
>>
>> Is there a way to pass 'this' in the timeout callback? I also use such
>> timeout callback to make the navgation buttons blink 3 times when the
>> photo is opened in full sizeā¦
>>
>
--
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.