setTimeOut problem

I'm trying to delay a function:
setTimeout(hypeDocument.functions().showGrp(hypeDocument, element, event) , 500);

But it doesn't work. What's the problem please?
I could use a timeline, but for some strange reason that doesn't work all the time.

TIA

setTimeout needs a function to trigger. When you got parameters the easiest way is to wrap it in a anonymous function.

Common approach:

setTimeout( function(){
    hypeDocument.functions().showGrp(hypeDocument, element, event)
}, 500);

When using timelines make sure to use startTimelineNamed instead of continueTimelineNamed because the latter doesn't restart by default.

Just for your information, you can actually do it as you intended but it get's a bit complicated because you would need to bind the parameters to the function name first:

setTimeout(hypeDocument.functions().showGrp.bind(null, hypeDocument, element, event), 500);

But that isn't the way most people do it because it gets rather confusing, quick.

2 Likes

That's it, thank you Max!