jQuery in Action

The jQuery plugin authoring guidelines
187
of this chapter, we'll examine the guidelines and patterns that allow us to create
jQuery plugins and we'll create a few of our own. In the following chapter, which
covers a completely different subject (Ajax), we'll see even more evidence that cre-
ating our own reusable components as jQuery plugins in real-world scenarios
helps to keep the code consistent and makes it a whole lot easier to write those
components in the first place.
But first, the rules...
7.2 The jQuery plugin authoring guidelines
Sign! Sign! Everywhere a sign! Blocking out the scenery, breaking my mind. Do this!
Don't do that! Can't you read the sign?
--Five Man Electric Band, 1971
Although the Five Man Electric Band may have lyrically asserted an anti-
establishment stance against rules back in 1971, sometimes rules are a good
thing. Without any, chaos would reign.
Such it is with the rules--more like common sensical guidelines--governing
how to successfully extend jQuery with our own plugin code. These guidelines
help us ensure, not only that our new code will plug into the jQuery architecture
properly, but also that it will work and play well with other jQuery plugins and
even other JavaScript libraries.
Extending jQuery takes one of two forms:
Utility functions defined directly on
$
(an alias for
jQuery
)
Methods to operate on a jQuery wrapped set (so-called jQuery commands)
In the remainder of this section, we'll go over some guidelines common to both
types of extensions. Then in the following sections, we'll tackle the guidelines and
techniques specific to writing each type of plugin element.
7.2.1 Naming files and functions
To Tell the Truth was an American game show, first airing in the 1950's, in which
multiple contestants claimed to be the same person with the same name, and a
panel of celebrities was tasked with determining which person was whom they
claimed to be. Although fun for a television audience, name collisions are not fun at
all when it comes to programming.


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

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