views:

128

answers:

3

setTimeout(target.mousedown, 200) doesn't seem to work. I can do setTimeout("target.mousedown()", 200), but this feels dirty.

What's the right way to do this?

+2  A: 

You can use an anonymous function:

setTimeout(function () {
  target.mousedown();
}, 200);

And you're right, you should always avoid using string parameters in setTimeout and setInterval functions.

CMS
+3  A: 

You might like this better:

setTimeout(function() { target.mousedown(); }, 200);
Warren Young
A: 

You haven't given us too much of your code but this definitely works:

var target = {
    mousedown: function() {
        alert('foo');
    }
};

setTimeout(target.mousedown, 200);
RaYell