HTML and CSS Reference
In-Depth Information
Functions are evaluated from the
inside out. This probably seems
intuitive; but to confuse the situa-
tion, it's possible to pass functions
as arguments to other functions.
Here's a simple function that
expects a function as a parameter:
function applyMe(f,n)
{return f(n);}
To pass the function as an argu-
ment, you specify the function
name without adding parentheses.
Passing functions as arguments is a
common pattern in calling HTML5
API s. It's also common to declare
simple, single-use functions
directly. This is called an inline
function : it's declared and then
thrown away. You can use it only
within the function it's being
passed to, not elsewhere in your
program, because there's no label
to refer to it.
That's all you need to know about functions—time to move on to
Functions let you group your code into convenient units that can then
be called in your program, but you'll also want to group data and func-
tions together. In JavaScript you do this with objects. In loose terms,
an object is a collection of stuff. The stuff can be variables, functions,
and other objects. JavaScript has several built-in objects, HTML
Search WWH ::

Custom Search