CHAPTER 3 n OBJECT-ORIENTED PROGRAMMING 79
Libraries
JavaScript libraries have been around in one form or another for almost as long as JavaScript
itself. As you go from project to project, it??™s inevitable that you??™ll find yourself reusing various
functions. They become part of your core that you end up copying each time you start up
something new.With any good library, code reuse leads to reliability; using the same code on
multiple projects means that the code has been exposed to more and more people, enabling
bugs or cross-browser issues to be resolved.
You can, of course, use someone else??™s library. Using an existing library such as Prototype
or jQuery gives you a higher level of reliability that might be difficult to attain through maintaining
your own code base.
The trade-off of using a library is file size. Some of these libraries, if taken as a whole,
weigh in at more than 300 kilobytes. However, library developers are tuned in to these kinds
of issues and are building their code in a very modular way, enabling you to pick and choose
only the features you need. This keeps the amount of code bloat to a minimum. Sites such as
Mootools.net even include a module picker that enables you to select whether to compress
the files or not.
Libraries serve a number of purposes, which I??™ve summarized into three categories:
??? Document object model (DOM) access, traversing, and manipulation
??? Application conveniences including language extensions
??? Widgets
Working with the DOM
Because you??™re working with HTML and Cascading Style Sheets (CSS), the DOM is likely the
most important interface when it comes to a solid library.
Pages:
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140