It may not always be obvious that in JavaScript you can pass functions as arguments to other functions.

Here is a simple example:

function test1(name){
    alert("test1 "+ name);
}

function test2(name){
    alert("test2 "  +name);
}

function test(name, func){
    func(name);
}

Test the functions:

test("Tom",  test1 );
test("Katie", test2 );

The resulting alerts will carry the following messages:

 test1 Tom
 test2 Katie

  A good article on functional programming techniques can be found at this site.

View top-rated JavaScript books from the amazon.com site