PencilCoder

Anonymous Functions!

Goals:

  • Make use of anonymous functions for callbacks
  • Further explore jQuery methods plan, done, and each.

Coding Snippets:

  • coding snippets
  • The jQuery each method facilitates iteration over the elements of a jQuery collection. This higher-order function accepts a callback with two arguments: the index of iteration and the current element.
  • plan delays execution of code passed to it, via a callback, until the appropriate point in the animation queue. In this example, plan ensures that the css statement is executed after the call to wear.

Math and Computer Concepts:

  • An anonymous function is defined without assigning it a name. Simply put the function definition where you normally would put a reference to a function.
  • Anonymous functions are particularly useful for defining callbacks that are used only once. Aside from saving coders a few keystrokes, use of anonymous functions reduces chances for namespace collisions: we don't have to worry that the name chosen for the function is a variable name already used elsewhere in our program.

Activities:

Save each of the following in a folder called AnonymousFcns.