New Perspectives On Web Design

(C. Jardin) #1
By Nicholas Zakas CHAPTER 2

where to do so. YUI, for example, has several different types of objects
available for extending the library.
If you want to add completely new functionality, then you create a
module. If you want to add more methods to DOM elements, then you cre-
ate a node plugin. There is always an answer to “How do I do this?” in YUI,
and that makes it easy to work with and extend.
Keep in mind that YUI’s system works well for a JavaScript library, but
you need different approaches depending on what you’re trying to create.
There are library architectures (such as YUI and jQuery’s plugin system),
framework architectures (Node.js module system) and application ar-
chitectures (Model-View-Controller or MVC). There are architectures for
every type of software and choosing one isn’t always easy. On the other
hand, not choosing one is the best way to ensure your code will become
unmanageable in short order.
Web developers traditionally don’t think about architecture very much
but that is starting to change. More and more, libraries and frameworks
with defined architectures are making their way into projects. JavaScript
and CSS for large applications, in particular, have benefited from a lot of
research into how code should be structured. Today, there are a number
of approaches and prebuilt solutions to help you create applications in a
logical way.


backbone.js


Backbone.js^3 is credited with starting the MV architectural movement in
JavaScript. Not a traditional MVC framework for its lack of a controller,
Backbone.js provides common patterns for manipulating views (HTML)
with structured data. A view can be automatically updated when the data
represented in the view changes. Backbone.js itself is pretty small and
doesn’t represent an entire architecture, but it can be a good building block
for a larger design.


3 http://backbonejs.org

Free download pdf