HTML and CSS Reference
1 A function called paint() is defined. It takes two parameters: a type and a color.
2 The local variable called str is assigned a string containing the value of type and
3 The variable tellme is a reference to an anonymous function. Defining a function
within another function is called a closure. This function will print the value of
str and a newline when it is called. But it is only defined here. It will not be called
until after the paint() function exits. Even though this function has no local vari-
ables of its own, it reuses the str variable declared in the outer function.
4 The paint() function returns the variable tellme whose value happens to be a ref-
erence to an anonymous function.
5 e t d l , a f e to t e ym s f ti n fi d wit in t e
paint() function, is assigned to say1 .
The returned value, a reference to the anonymous function defined within the
paint() function, is assigned to say2 .
Let's look at the value of the variable say1 . In the alert box (Figure 7.13) you can
see that the value of say1 is the complete definition for the anonymous function
declared on line 3.
By adding parentheses to the reference say1 , so that now it is say1() , the anony-
mous function is called and the statement within it is displayed (see Figure 7.14).
The variable say2 is also a reference to an anonymous function; say2() calls that
Figure 7.13 The value of the variables, say1 and say2 , is a function definition.