0

I'm running through JavaScript: the Definitive Guide
It offers up the following code to explain setTimeout() and setInterval(), and my issue is that it runs in Safari without issue but in Mozilla it doesn't seem to trigger at all, anyone have any thoughts?

The issue is in the following function:

function invoke(f,start,interval,end){
        if(!start) start=0; //default to 0ms (start right away)
        if (arguments.length <= 2)
            setTimeout(f,start);

It functions if I don't set the inverval and end, but if I do something goes janky

    else{
        setTimeout(repeat,start);
        function repeat(){
        var h = setInterval(f,interval);
        //if(end)setTimeout(function(){clearInterval(h)},end);
        }
    }
    }

This is just the dummy function that runs on setTimeout() and setInterval()

    function f(){
    if(true)
        alert("yo");
    }



<button onclick="invoke('f,200,1000,5000')">yo</button>

Hopfully somone has some insight into this one, thanks.

1
  • What actually happens when you run it with the interval? janky isn't a very descriptive term and last I looked wasn't in my programming dictionary. Did you try it without a blocking alert? Try using just a console.log() instead. Commented Mar 2, 2012 at 14:50

3 Answers 3

1
<button onclick="invoke('f,200,1000,5000')">yo</button>

should be

<button onclick="invoke(f,200,1000,5000)">yo</button>

Otherwise you are passing the string 'f,200,1000,5000' as the first parameter.

Sign up to request clarification or add additional context in comments.

Comments

0

JSFiddle this now appear to work,

as the others have said you need to remove the 's arround your parameter to invoke

also FireBug for firefox ( get it if you dont already ) fails with Repeat is undefined so I've also modified that a little too.

Comments

0

It looks like you're passing a single variable to your invoke function due to the placement of your second single quote. Try changing it to

<button onclick="invoke('f',200,1000,5000)">yo</button>

and see if that works any better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.