Reputation: 89193
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?
Upvotes: 0
Views: 473
Reputation: 70414
You haven't given us too much of your code but this definitely works:
var target = {
mousedown: function() {
alert('foo');
}
};
setTimeout(target.mousedown, 200);
Upvotes: 0
Reputation: 42333
You might like this better:
setTimeout(function() { target.mousedown(); }, 200);
Upvotes: 3
Reputation: 827218
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.
Upvotes: 2