Using JavaScript

JavaScript is, as Douglas Crockford puts it, a very misunderstood programming language. These tutorials are designed to provide an overview, with examples, of the some of the power of this programming language. Since the advent of AJAX, and more recent developments such as Google Gears, the importance of being able to program well in JavaScript has grown enormously.
The tutorials are not just aimed at the developer who works on code for the browser or client side. I have made presentations to classic ASP developers, in an attempt to move them away from VBScript and towards JScript, for web application development. There are also many other implementations of JavaScript interpreters within web servers available, apart from IIS.
Together with this series of tutorials, I have also made available two compressed archives; Scripts.zip and AspScripts.zip.
The first (which is about 20KB in size) contains the JavaScript code used in these tutorials. This can be used for your client side projects, as the code is distributed under the GNU Lesser General Public License.
The second (which is about 100KB in size) is a small, but complete ASP project, using exactly the same code as the first. It is designed to be a starting point for your classic ASP web application development, as the code is also distributed under the GNU Lesser General Public License. Unzip the contents into your IIS wwwroot directory, create a Virtual Directory called AspScripts, set the default document to index.asp, then point your browser to http://localhost/AspScripts/.

The Tutorials

I will not attempt to introduce you to the syntax of JavaScript. This has already been done in an excellent paper by Simon Willison, entitled “A (Re)-Introduction to JavaScript”, prepared for a presentation he gave. He has also generously made slides available of the presentation.
The first tutorial looks at one of the dynamic aspects of JavaScript - being able to introspect an object to discover its properties. Apart from being a useful debugging tool, it also introduces simple namespacing, and recursion.
The second tutorial investigates inheritance, adding functions to existing objects, via prototypal inheritance. JavaScript is not a restrictive programming language, you can add methods and properties to even built-in objects.
The third tutorial discusses closures, which are used primarily in JavaScript to create private properties, using inner functions.
The final tutorial builds a small library to generate XML. This is by far the largest of the tutorials, so it is split into design, the code, and the example. The emphasis is on using the least possible amount of code to just do the job in hand.

Further Reading

Douglas Crockford has spent a lot of energy explaining the power and versatility of JavaScript. I highly recommend reading all the articles he has published, which he has grouped together on this page. There are also links to a series of presentation videos, ranging from 30 to 60 minutes. Again, there is much valuable information to be found here, and I think that you will find the time well spent.
He has also created the JSLint program. This program checks the construction of Javascript programs, and offers suggestions to improve the code, and reduce potential errors.
There is a JSDoc tool to create HTML documentation from specially formed documentation comments in the JavaScript source code. It follows a very similar syntax to Java's javadoc tool.

Contacts

Syger can be contacted for consultancy work on any of the topics mentioned in this article, by sending an email to info@syger.it.

Valid CSS

Valid XHTML 1.0

Valid Atom 1.0