The 2000 is the total time that the animation runs.
If we increase it, the animation takes longer to make the same changes, so the animation is slower.
CSS is probably better because it's built-in. But we can do things with JS/JQ that we can't do with CSS animations, like running arbitrary JS code during the animation, which we'll do later this semester.
Sure. First, document
is just the thing that we attach the event handler to.
In this case, we want the keyup
event handler to apply anywhere in the document (the web page)
The code prevents any default behavior (probably nothing, but just in case)
It keeps the event from going further up the tree.
It prints out some useful information.
It's the function that gets run when we click
on the
element whose id
is run2
.
Sure. A closure is a function plus an environment.
The environment gives values to unbound variables.
A closure is useful whenever we need a function that remembers something from its "birth environment."
In Ottergram, we need each event handler to remember which thumb it was attached to.
A unbound variable is one that is used but not defined within a function body.
A closure variable is an unbound variable that gets its value from the environment of the function.
As an example, let's look again at the shopping example
We have the makeCounter
example. Everything else is based on that.
The lexical (textual) environment that the function is defined in. In other words, the code around the function definition.
In the code above,a
, b
, and c
are all closure variables,
and outer
is the environment.
We put the function back into an environment that gives values to the unbound variable, namely thumb
.