O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding MooTools ubiquitous anonymous functions

Functions have names, but anonymous functions do not; MooTools uses them everywhere.

Note

Anonymous functions are one-time use like disposable lighters. In MooTools, we use them to one-time define a method; reusable disposable functions!

Getting ready

To define and call an anonymous function raw JavaScript wraps a function in parentheses:

(function(){document.title=location.href;alert('done');})();

Nothing is returned, and the function is not assigned to a function identifier; when the () function syntax is appended, the function self-executes.

How to do it...

MooTools' use differs slightly in that we will pass this anonymous function as an argument to a MooTool object and bind it to an identifier; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required