Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Callback Functions in JavaScript!
You have completed Callback Functions in JavaScript!
Preview
In this video, we'll explore using anonymous functions with `setInterval`.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
I challenge you to try and
0:00
use an anonymous function with
the setInterval function.
0:02
And to think if it's possible to
use one with our clock application.
0:05
While it is possible to use an anonymous
function with the set interval function,
0:10
we shouldn't really use one in this
application, let me show you why.
0:15
Let me cut and paste tickClock into this
0:20
setInterval function,
and make it anonymous.
0:25
But what happens to the tickClock
invocation outside of the setInterval?
0:32
We don't have the function
to call anymore,
0:38
let's comment out this line,
save, and preview it.
0:41
We see clock goes here, and then it starts
ticking, this behavior is not desirable.
0:49
Because we need to update the clock
display when the page loads,
0:55
we can't wait for
the first setInterval call.
0:59
The clock application isn't really
suited for an anonymous function.
1:03
So I'm going to revert my code back to
include the named function, tickClock.
1:08
Being comfortable using named and
1:16
anonymous callbacks in other functions is
required for any JavaScript programmer.
1:18
After you've experimented with the code,
you'll need to exercise judgment.
1:24
And when you start making
judgment calls like that,
1:28
you're becoming a more mature developer
1:30
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up