02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

246<br />

CHAPTER 7 ■ ENHANCING THE USER INTERFACE WITH JQUERY<br />

Figure 7-1. Clicking an event title causes a modal window to appear<br />

USING AN OBJECT LITERAL FOR UTILITY FUNCTIONS<br />

Utility functions often come into play when writing applications. The more complex the app, the more likely<br />

it is that a large number of utility functions will exist for it, <strong>and</strong> the harder it is to keep those functions<br />

organized.<br />

One option for keeping utility functions organized is to use object literals. This allows developers to put the<br />

functions in one place or even to group functions according to their usage.<br />

Underst<strong>and</strong>ing Object Literals<br />

At its simplest, an object literal is a variable in JavaScript that is an empty set of curly braces, signifying an<br />

empty object literal:<br />

var obj = {};<br />

You can add any number of values to the object literal using comma-separated name-value pairs:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!