jQuery in Action

Manipulating JavaScript objects and collections
167
<script type="text/javascript">
var $ = 'Hi!';
jQuery(function($){
alert('$ = '+ $);
});
</script>
The only change we made was to add a parameter to the ready handler function
named
$
. When we load this changed version, we see something completely dif-
ferent as shown in figure 6.4.
Well, that may not have been exactly what we might have predicted in advance.
But a quick glance at the jQuery source code shows that, because we declare the
first parameter of the ready handler to be
$
within that function, the
$
name
refers to the
jQuery
function that jQuery passes as the sole parameter to all ready
handlers (so the alert displays the definition of that function).
When writing reusable components, which might or might not be used in
pages where
$.noConflict()
is used, it's best to take such precautions regarding
the definition of
$
.
A good number of the remaining jQuery utility functions are used to manipu-
late JavaScript objects. Let's take a look at them.
6.3 Manipulating JavaScript objects and collections
The majority of jQuery features implemented as utility functions are designed to
operate on JavaScript objects other than the
DOM
elements. Generally, anything
Listing 6.3 Ready handler test 2
Figure 6.4 The alert now displays the jQuery version of
$
because its definition has
been enforced within the function.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.