วันจันทร์ที่ 12 มกราคม พ.ศ. 2552

Working with JavaScript

Today, most websites tend to use JavaScript in order to add client-side interactivity and logic—whether
it is simply to change the appearance of a button when the user hovers over it with their mouse or
whether it is to create something much more complex such as an entire user interface in the vein of
the Fluxiom web application
At the heart of Fluxiom is a scripting language based on the ECMAScript specification, with a syntax that
should be familiar to anyone who has done any Java or ActionScript programming. The ECMAScript
specification itself is an international standard, of which both JavaScript and ActionScript are dialects.
JavaScript is a universal technology, available in every major desktop browser and even on mobile
devices such as the latest Nokia phones and, of course, the iPhone. Despite a spotted past of incompatibilities
and proprietary functionality, the language has reached a point of maturity where it has
become pretty much standardized in implementation, with various frameworks offering up conventions
as to how developers should be using the language. The popularity of common component
frameworks has also helped support its usage by developers across the Web.
Frameworks often provide developers with components and utility classes that can be leveraged when
building more complex applications. They often reduce the amount of headaches that a developer has
to deal with by implementing generic functionality such as object orientation, garbage collection,
visual effects, and rich user interface components, while at the same time providing solutions to common
cross-browser programming challenges (a diplomatic phrase for bugs!). This reduces development
time and negates the need to reinvent the wheel when producing a simple web application.
Many frameworks are available, ranging from fully blown affairs encapsulating all of the utility functions
that you will likely need when building a web application, including data communication and
DOM manipulation, to simple reusable components that might implement a specific user interface
element such as a slider or accordion. Depending on whom you ask, you will often get recommendations
for different frameworks, and often their suitability will vary depending on the project. Of particular
interest are MooTools (www.mootools.net) and jQuery (www.jquery.com); both provide a great
deal of features given their small file size and offer exceptional performance.
In major projects, a framework is often considered essential, whether it be an off-the-shelf one such
as those mentioned here or something homegrown. They often make larger projects more manageable,
standardizing development and encouraging reuse.
The use of JavaScript in mashups is varied, because often it is necessary to augment it with server-side
scripting that performs data aggregation and other pieces of logic/processing—both tasks that could
have performance overhead if performed using JavaScript on the client. In these cases, JavaScript is
used mainly to provide a rich, interactive user interface and to allow asynchronous communication
with the server using the XmlHttpRequest object (a JavaScript object that is used to make asynchronous
calls to a web server).
When developing more complex mashups using an HTML/CSS/JavaScript front-end, a server-side component
to handle the aggregation of data from various sources or to store user preferences often
becomes essential.
JavaScript also runs within a tight security model, restricting access to domains other than the one
from which the script was loaded. There are ways around this; however, this can also impact connectivity
with external application programming interfaces (APIs) and data services.
That said, it is possible to consume external data services using JavaScript as part of a web application
with some creative workarounds. A good example of this is the incorporation of an interactive Google
map within a web page.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น