Object Oriented JavaScript Notes

Functions as Data

Pages 356-362 of Chapter 8 of Fundamentals of Web Development explain how functions are data (objects) and can be assigned to variables, passed as parameters, and so on. This concept will be important to understand when we look at Ajax later in the term. The concept of closures (pages 368-370 of Ch. 8) is also useful when working with Ajax.

JSON

Object literals (see page 353 of Fundamentals of Web Development) in JavaScript are the basis for JavaScript Object Notation (JSON). JSON is sometimes used as an alternative to XML because a JSON object literal is often shorter and simpler than an equivalent XML document.

You can learn more about JSON at http://json.org The web site has links to a number of JSON libraries for various programming languages. Fundamentals of Web Development has a short introduction to JSON on pages 889-891. We will look at JSON (and XML) later in the term.

No classes in JavaScript

There are no class definitions in JavaScript (prior to ECMAScript 6). Instead, you can use constructors and prototype objects to do things that might be done with classes in Java, C++, or C#. You can read about constructors and prototypes in Chapter 8 of Fundamentals of Web Development. More recent versions of JavaScript have a class keyword and syntax for defining classes but we won't be using class definitions.