Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-09-2009, 08:16 PM   PM User | #1
schotte
Regular Coder

 
Join Date: Nov 2004
Location: Edinburgh, SCO
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
schotte is an unknown quantity at this point
[jQuery] setTimeout issue

Hey all,

as I mentioned in the title, I've an issue getting setTimeout to work inside a plugin I am developing.

Code:
$.Plugin = function(obj,opt)
{
     init();
     
     function init() { ... };
     function heartbeat() { ... };

     setTimeout('heartbeat();', 1000);
}
Error: heartbeat is not defined

Anyone dealt with this before?

Cheers

Last edited by schotte; 08-10-2009 at 08:49 AM..
schotte is offline   Reply With Quote
Old 08-10-2009, 04:16 PM   PM User | #2
edric
New to the CF scene

 
Join Date: Aug 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
edric is an unknown quantity at this point
Quote:
Originally Posted by schotte View Post
Hey all,

as I mentioned in the title, I've an issue getting setTimeout to work inside a plugin I am developing.

Code:
$.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

Code:
$.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.
edric is offline   Reply With Quote
Old 08-13-2009, 01:08 PM   PM User | #3
Uzbekjon
New Coder

 
Join Date: Feb 2009
Location: Uzbekistan
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Uzbekjon is an unknown quantity at this point
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...

Code:
function heartbeat() { ... };

$.Plugin = function(obj,opt)
{
     init();
     
     function init() { ... };

     setTimeout('heartbeat();', 1000);
}
Uzbekjon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 AM.


Advertisement
Log in to turn off these ads.