i want to do a setInterval of a function that is at the same level as the declaration of the setinterval but not global
Example:
function a()
{
function b(){alert("hi");}
setInterval("b()",1000);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your example, simply use
setInterval(b, 1000)instead ofsetInterval("b()", 1000).I’d go as far as to say you should always use
setIntervalandsetTimeoutwith a real function instead of a string.