The magazine of the Melbourne PC User Group

Learning JavaScript - for the bookshelf
Major Keary
 

JavaScript is an interpreted programming language, which means it requires software that processes instructions on-the-fly. The interpreter is built into Web browser software, so you don't have to install it. The attraction of JavaScript is that you can learn just enough to satisfy your needs — it is not necessary to learn the whole thing from A to Z.

Unrelated to Sun's Java programming language, JavaScript was introduced by Netscape in 1995, initially under the name LiveScript. Microsoft later released its own version, JScript, that was not quite the same. In order to resolve "compatibility issues Netscape submitted the JavaScript specification to the European Computer Manufacturers Association (ECMA) ... in 1996 ... [seeking to have it reissued] as a standardised work" [Powers: Learning JavaScript]. In 1997 the ECMAScript specification was released as ECMA262, of which version 3 is identical with JavaScript 1.5 and JScript 5.6. There have since been further developments: JavaScript 1.7 is implemented in FireFox 2; and ECMA-357 (2004) includes an extension, E4X, that includes native XML.

For a while it looked as if JavaScript was going out of fashion, but it has become a key element of new Web technologies — especially Ajax —that have created a resurgence of interest and new developments. The changes from version to version —and between different vendors — don't seem to present many problems; older versions are still in use depending on the browser. Any difficulties, according to Shelley Powers (LearningJavaScript) are more likely to be caused by "differences in the underlying Document Object Model (DOM)", which is unlikely to present any problems for ordinary users. Those who have used pre-Ajax JavaScript will find there have been some changes, as the author of LearningJavaScript observes:

" ... Ajax developers have created libraries to make the language look more like Ruby or Python or even Java. However, they've also added all sorts of odd semantics into Ajax applications, with little or no documentation, and obscure references to items such as 'function closures, and so on. ... So the you have JavaScript books and libraries that are focussed on the old styles of Web page development, and new Ajax libraries and books on the new style ... ".

Shelley Powers describes JavaScript as two languages in one: the first is a fast, friendly, easy-to-use scripting language built into Web browsers and other applications, offering a range of functions; "the second is a mature, full-featured, carefully constrained, object-based language, which does require more in-depth understanding". That is why there is a wide range of JavaScript texts; one does not have to embrace Ajax or other new Web technologies to use — or just understand — JavaScript. If you want to learn JavaScript for use at the simple level there are some very good resources for beginners, both in print and on the Web.

JavaScript in Easy Steps

Computer Step publishes books designed to take novices through a topic in easy steps. At first glance they may appear to be graphics-based (big on pictures and short on words), but in these titles the generous use of screen shots is there to illustrate the end result of detailed and annotated code examples.

In this instance the topic is JavaScript. The present (third) edition of JavaScript in Easy Steps includes descriptions of Ajax and DOM. Ajax is a method of using existing technologies to create Rich Internet Applications (RIA) that behave in much the same way as a desktop application. The Document Object Model (DOM) is now a W3C standard observed by most (if not all) browser vendors, which makes JavaScript even more useful.

This book is not a hand-holding presentation, but — as its title says — takes the reader through client-side JavaScript in easy steps. Like all programming languages, JavaScript has its keywords, syntax, variables, data types, functions, and so on. The author makes each element the topic of a separate discussion that is contained in either a single page or a two-page spread. In each instance example code is used to illustrate the text. It is thorough and comprehensive, and the style is straightforward. Readers are assumed to be computer literate and to have a working knowledge of HTML.

JavaScript in Easy Steps is a plain language tutorial that doesn't engage in jolly banter or humorous asides. If you want to use, and understand, JavaScript JavaScript in Easy Steps is highly recommended. If not available at your usual book shop it can be obtained from the Australian distributor at http://www.woodslane.com.au.
 

Mike McGrath: JavaScript in Easy Steps 3/e
ISBN 978-1-84078-315-5
Published by Computer Step,
192 pp.,
RRP $29.99 incl. GST

Foundation Web Design

This title is published by friends of ED, an imprint of Apress. Foundation Web Design is a tutorial on Web design and has been included with JavaScript titles because it places JavaScript in the big picture of Web design. Designing and creating Web pages is becoming more complex, which makes it difficult to find texts that suit the needs of users who don't need the latest technologies. It also provides lucid discussions that explain how and why things work, the kind of knowledge that some texts expect readers to bring to the table.

A case study is used throughout to illustrate the design of a professional Web site. Example code and useful illustrations support the text. JavaScript is one topic, but it is placed in the context of the other tools (HTML and CSS) necessary to advanced Web design.
The focus is on essential skills and step-by-step instructions. An excellent starting point for Web novices who want to learn how to create a Web site from scratch. Don't be put off by the publication date (2003); for novices and intermediate-level users that is an advantage because it does not introduce unnecessary complexities. Foundation Web Design will lay a solid foundation for those who want to advance their skills.

If your bookshop doesn't have Foundation Web Design in stock it can be obtained from the Australian distributor, Woodslane, at http://www.woodslane.com.au.
 

Sham Bhangai and Tomasz Janowski: Foundation Web Design
ISBN 1-59059-152-6
Published by Apress,
423pp,
RRP $55.00 incl. GST

Modern Web Design with JavaScript and DOM

From the impressive stable of SitePoint, DHTML Utopia: Modern Web Design Using JavaScript & DOM has been written for "people who have built Web sites before" and who have experience working with HTML and CSS. Even though it has been in print for eighteen months — which can be a long time in computer literature — the book is still a highly relevant and useful JavaScript resource. In particular, there is an excellent explanation of the Document Object Model (DOM), a term that crops up a lot in Web technology literature.

If a Web page offers, or requires nontrivial user input it needs DHTML (Dynamic HTML), which is "a combination of proper HTML for your content, Cascading Style Sheets for your design, and JavaScript for interactivity". 'Proper HTML' means valid HTML: it complies with the rules for how HTML should be written and which specify that tags should be properly nested (no cross-overs); container tags should be closed; and a Document Type is mandatory.

The DOM "provides access to the structure of an HTML page by mapping the elements in that page to a tree of nodes". If you want to use DHTML it is necessary to understand DOM. Modern Web Design contains a very clear explanation of what it is and how it is used. In the book an example shows how DOM is used to build a form that grows as the user fills it in.

Sounds complex? It doesn't have to be. The author walks his readers through all aspects of building a dynamic Web site using JavaScript and DOM. The content is presented in tutorial format, but is not confined to bare-bones instruction. The text is supported by extensive use of annotated example code that can be downloaded from a companion Web site. The annotation are not terse, and include lucid explanations of why something is done and how the code works. Topics covered extend to advanced concepts (such as multilevel drop down menus), remote scripting, and communicating with the server.

An instance of the book's thoroughness is a discussion of detecting browser features rather than simple `browser sniffing'. The modern technique is to test for the necessary features — such as DOM compliance — rather than identify the `make' of browser. A dynamic Web site can be built to cope with browsers that lack a full complement of preferred features.

This book has an extraordinary depth of detail, but maintains a focus on practical issues and is written in a style that won't leave the reader floundering. It is not for novices, but anyone with a reasonable understanding of building Web sites should be able to follow the tutorial without difficulty. SitePoint doesn't release many books, but those it does publish are of remarkable quality.
 

Stuart Langridge:
DHTML Utopia: Modern Web Design Using JavaScript & DOM
ISBN 0-9579218-9-6
Published by SitePoint,
318 pp.,
RRP $74.95 incl. GST

Learning JavaScript

This title is more comprehensive than, those mentioned above and has been prompted by the new prominence of JavaScript as a key part of Ajax. Readers are not expected to have programming experience, but are expected to be familiar with HTML/ XHTML and CSS, and have a grasp of how Web applications work. The book serves as a bridge between the old-style and new-style JavaScript and is especially useful for "those learning JavaScript because they want to jump into Ajax".

Even though the book's primary audience is Web designers and programmers, anybody "who wants, or needs, to integrate JavaScript into [a] personal Web site or sites ... [or] who uses a content-management tool, such as a weblogging tool, and wants to better understand the scripting components ... " will find this a comprehensive and detailed introduction. It is not a learning tool for novices, who should begin with JavaScript in Easy Steps.

For those who are serious about learning JavaScript there are questions set at the end of each chapter — answers at the back of the book. Extensive use is made of example code (available for download from a companion Web site) to illustrate the text; code examples are extensively annotated.

Throughout the book there are valuable asides that include tips, suggestions, and general notes amongst which are best practice recommendations such as: Take advantage of short-circuit evaluation by placing the key expression or less resource-intensive expression first when using logical AND/OR operators. There are also boxed items that introduce other programs/tools, such as phpFormGenerator, Eclipse, and free JavaScript editors for Windows, and JavaScript compression/obfuscator utilities. In addition to that collection of information there is a chapter that describes a selection of free libraries and frameworks (with URLs).

Learning JavaScript does not pretend to be a definitive guide; however, it is remarkably comprehensive and provides discussions of topics that are not found — at least in any useful detail — in most other general JavaScript texts. Security, cookies, and cross-site scripting (XSS) attacks are some of those topics.

Anyone approaching JavaScript with intention to learn, or extend their knowledge, should have this title. Good value.
 

Shelley Powers: Learning JavaScript
ISBN 978-0-596-52746-4
Published by O'Reilly,
335 pp.,
RRP $55.00 incl. GST

JavaScript: The Definitive Guide

JavaScript: The Definitive Guide has been a pre-eminent JavaScript resource since it was first released in 1996 and is now in its fifth edition. Since the last edition (2002) there have been significant changes in the JavaScript landscape, as the author notes: "Google released their Gmail application and people noticed that it didn't behave like the Web sites they were used to. And Jesse James Garrett published his seminal essay on this new style of Web development, which he christened Ajax. All of a sudden, the world of JavaScript had changed". It is now being used to write "programs that are an order of magnitude longer than the scripts that most of us were writing five years ago". JavaScript is being used in a much more complex way by developers, and is an integral part of advanced technologies such as Ajax. There are two faces to JavaScript: client-side and server-side; most texts are confined to client-side, but this title covers both.

In spite of those developments JavaScript can still be used at a simple level; ordinary users don't have to make a choice between what they have been doing — the simple life —and the complexities of 'modern' JavaScript. Developers and professional Web designers need JavaScript in its new role, and JavaScript: The Definitive Guide has been updated for that audience.

Of course, if you are a user of simple JavaScript who wants to get up to speed with the latest developments this is the perfect companion to Shelley Powers' Learning JavaScript.

An example of what can be done, and which is discussed in JavaScript: The Definitive Guide, is scripting Java (the programming language). It is possible to embed a Java Script interpreter within a Java application and have JavaScript, running within that application, script Java
objects. That, of course, is a topic of interest to Java programmers, but it indicates the way in which JavaScript has been extended.

The book has been divided into parts so as to separate core JavaScript material from client-side JavaScript, thus making it more convenient for programmers working in other than a Web browser an environment. In order to fit all the material in even as large a book as this, the reference entries are terse. For programmers —the principal audience — who know JavaScript, but who need a reference, that terseness is an advantage: information is specific, easy to find, and is not burdened with superfluous verbiage. In the explanatory sections the language is clear and the style concise, but eminently readable. Extensive use of example code supports the text; the code — and any errata discovered after publication —is available for download from a Web site.
 

David Flanagan: JavaScript: The Definitive Reference 5/e
ISBN 978-0-596-10199-2
Published by O'Reilly,
994 pp.,
RRP $85.00 incl. GST

Reprinted from the Jan / Feb 2007 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[ About Melbourne PC User Group ]