Chapter 2. JavaScript


The ability to embed scripts in web pages is key to making them more interactive. Scripts can be used to respond to events, such as the loading of a web page or the click of a button by a user, and are the means for dealing with data sent to and from the server via HTTP requests and responses.

For most web developers, JavaScript is the script language of choice, since it is the only language supported by all major browsers. Although an Ajax framework like Atlas makes it easy to use the technology without having to know too much about its details, a sound knowledge of JavaScript is, in my view, absolutely mandatory to make the most of Atlas (but Atlas can even help developers not familiar with JavaScript at all, thanks to the framework approach). Since Atlas is a framework, without the ability to use JavaScript, you are limited to the functionality exposed by the Atlas controls. Some client scenarios actually require more work in Atlas than when using custom JavaScript. Therefore, the best strategy for a modern Ajax-enabled web site is to use the best of both worlds: the Atlas framework extended with your JavaScript code.

JavaScript: A History

The JavaScript language was created by Netscape engineer Brendan Elch in the 1990s. Originally called Mocha, it made its first appearance in the third beta version of Netscape Navigator 2.0 in 1995. Later that year, Netscape arranged with Sun Microsystems, owner of the Java language, to rename the language to JavaScript (after calling it LiveScript for some time). This has led to confusion ever since, because JavaScript and Java do not share any similarities at all, with the exception that they're both C-style languages.

JavaScript enabled HTML pages to be really dynamicincluding instant form data validation, graphical effects, user interaction, and much more. In a time when bandwidth was limited (most users had slow dial-up lines) and server roundtrips costly in time, JavaScript gave web developers a tool to make their sites more interactive. When JavaScript took off, Microsoft added scripting capabilities to its own browser, Internet Explorer, as well. For copyright reasons, however, they named their version of the language JScript, but it was a JavaScript work-alike.

In 1997, the browser war between Netscape Navigator (still the market leader) and Internet Explorer (soon to become the market leader) reached a climax. Netscape 4 was released in June, introducing JavaScript Version 1.2 with new capabilities. In the same month, the ECMA standard ECMA-262 was announced, which formalized the scripting language (see http://www.ecma-international.org/publications/standards/Ecma-262.htm). JavaScript, therefore, is an implementation of ECMA-262 or ECMAScript.

In October of the same year, Internet Explorer 4 was released, supporting only JavaScript 1.1 (and VBScript, a scripting language based on Visual Basic; we do not address VBScript here because it runs only in Internet Explorer and is therefore not relevant for browser-agnostic client scripting). At that point, the browsers were quite incompatible, especially when it came to implementing effects like positioning and moving elements. The mix of technologies used to achieve these kinds of effects has been dubbed Dynamic HTML (DHTML). Despite popular belief, DHTML is not a standard at all, but a fabricated term, just like Ajax.

Then, things changed dramatically. Netscape scrapped an almost-ready Version 5 of its browser and decided to rewrite it from scratch. This led to an immature Version 6 of Netscape, based on the new open source Mozilla project and the Gecko rendering engine. The delays and the quality issues of the browser cost Netscape their market share, and Internet Explorer took the lead.

However, development of Internet Explorer stalled with Version 6, and the Firefox browser (also based on Mozilla but only the browser, not additional features such as mail or news reader) started reclaiming some of Internet Explorer's market share. Internet Explorer 7 is currently available as a beta, so the race is on again.

From a JavaScript point of view, not very much has changed in recent years. After the death of Netscape 4, the major browsers (which include Internet Explorer and Mozilla, as well as Safari, Konqueror, and Opera) are relatively compatible to each other (regarding their JavaScript support), although some differences and issues remain.

The lack of innovation in browsers also held back widespread use of Java- Script, and books on the topic received very few updates in the last couple of years. However, this all changed with the invention of the term Ajax. Although the technology behind Ajax has existed since 1998, it only recently moved into mainstream web programming. Chapter 3 covers this in more detail.


Of course this book is about Atlas, so a complete overview of JavaScript is out of place. The aim of this chapter is to provide you with a good foundation so that you can use and understand the examples in this book. The following details on JavaScript are far from complete and focus only on its most important features. For more information on JavaScript, please refer to the resources listed in the "For Further Reading" section at the end of the chapter.




Programming Atlas
Programming Atlas
ISBN: 0596526725
EAN: 2147483647
Year: 2006
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net