jQuery in Action

188
CHAPTER 7
Extending jQuery with custom plugins
We'll discuss avoiding name collisions within our plugins, but first let's address
naming the files within which we'll write our plugins so that they do not conflict
with other files.
The guideline recommended by the jQuery team is simple but effective, advo-
cating the following format:
Prefix the filename with jquery.
Follow that with the name of the plugin.
Conclude with .js.
For example, if we write a plugin that we want to name Fred, our JavaScript file-
name for this plugin is
jquery.fred.js
The use of the jquery. prefix eliminates any possible name collisions with files
intended for use with other libraries. After all, anyone writing non-jQuery plu-
gins has no business using the jquery. prefix.
But that leaves the plugin name itself still open for contention within the
jQuery community.
When we're writing plugins for our own use, all we need to do is avoid conflicts
with any other plugins that we plan to use. But when writing plugins that we plan
to publish for others to use, we need to avoid conflicts with any other plugin that's
already published.
The best way to avoid conflicts is to stay in tune with the goings-on within the
jQuery communityPlugins; but, beyond being aware of what's already out there, there are other pre-
cautions we can take.
One way to ensure that our plugin filenames are unlikely to conflict with oth-
ers is to sub-prefix them with a name that's unique to us or our organization. For
example, all of the plugins developed in this book use the filename prefix
jquery.jqia (jqia being short for jQuery in Action) to help make sure that they won't
conflict with anyone else's plugin filenames should anyone wish to use them in
their own web applications. Likewise, the files for the jQuery Form Plugin begin
with the prefix jquery.form. Not all plugins follow this convention, but as the
number of plugins increases, it will become more and more important to follow
such conventions.
Similar considerations need to be taken with the names we give to our func-
tions, whether they're new utility functions or methods on the jQuery wrappers.


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

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