Chapter 2. Object Orientation

Object orientation has been at the heart of many types of software for years, but web developers using JavaScript and server-side scripting languages generally haven’t been as fast to embrace it. In the early days, websites had fairly simple scripting needs, so object orientation wasn’t crucial. Today, with the complexity of software on the Web, an understanding of object orientation is fundamental to approaching the development of large web applications with the same rigor as other types of software.

Throughout this book, we’ll explore many examples that use object orientation in PHP and JavaScript, so it’s worth spending a little time to examine its importance and how both languages address it. Both PHP and JavaScript have powerful support for object orientation, but each implements it in different ways. One of the fundamental differences is that PHP is a class-based language. In class-based languages, you declare and extend classes, which you then instantiate as objects wherever needed. This is object orientation as C++ and Java developers know it. On the other hand, JavaScript is a prototype-based (or object-based) language. In prototype-based languages, there are no classes; you create objects on the fly and derive new ones using existing objects as prototypes. Whatever the language, the following tenet (first described in Chapter 1) articulates what we expect to achieve with an object-oriented implementation:

Tenet 2: The use of object orientation ...

Get Developing Large Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.