View Full Version : [jQuery] setTimeout issue
schotte
08-09-2009, 09:16 PM
Hey all,
as I mentioned in the title, I've an issue getting setTimeout to work inside a plugin I am developing.
$.Plugin = function(obj,opt)
{
init();
function init() { ... };
function heartbeat() { ... };
setTimeout('heartbeat();', 1000);
}
Error: heartbeat is not defined
Anyone dealt with this before?
Cheers
edric
08-10-2009, 05:16 PM
Hey all,
as I mentioned in the title, I've an issue getting setTimeout to work inside a plugin I am developing.
$.Plugin = function(obj,opt)
{
init();
function init() { ... };
function heartbeat() { ... };
setTimeout('heartbeat();', 1000);
}
Error: heartbeat is not defined
Anyone dealt with this before?
Cheers
try this
$.Plugin = function(obj,opt)
{
init();
function init() { ... };
function heartbeat() { ... };
setTimeout(heartbeat, 1000);
}
no braces no parentheses just pass the function object itself instead of a string.
Uzbekjon
08-13-2009, 02:08 PM
The problem is that javascript can not find heartbeat() when it's being run. You should either declare your function out of the plugin (global namespace) or refer to your function with the full path ($.plugin.func()). Of course you'd need to rewrite your code a little...
function heartbeat() { ... };
$.Plugin = function(obj,opt)
{
init();
function init() { ... };
setTimeout('heartbeat();', 1000);
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.