September 15, 2007

September 07 Meeting - Creating JavaScript Objects

The more advanced JavaScript applications get, the greater the need for structuring the code well. One way to do this is by using OOP, object-oriented programming. JavaScript itself is not an object-oriented language, but rather an object-based language. There is a support for OOP, though it's somewhat limited.

There is no distinctive keyword for classes in JavaScript. Instead, each class is defined as a function. The difference between a regular function and this one is the way this function is later called: with the new keyword.

Each JavaScript object is based on another object known as, appropriately enough, Object. The object you create is actually an “extension” of the base Object. No matter what technique discussed today to create a JavaScript object (constructor, prototyping or object literal notation), you can then create properties and methods to this new custom object.

This topic will be the foundation for the rest of what we discuss in this workshop. This season's theme will be JavaScript libraries.

For more information on creating custom objects besides the presentation and code examples, checkout these references:

Mozilla Development Center: Creating Objects

JavaScript Kit: Object Oriented Programming

MSDN Magazine: Object Oriented Techniques with JavaScript