Book Image

Object-Oriented JavaScript

Book Image

Object-Oriented JavaScript

Overview of this book

Table of Contents (18 chapters)
Object-Oriented JavaScript
Credits
About the Author
About the Reviewers
Preface
Built-in Functions
Regular Expressions
Index

Chapter 6. Inheritance

If you go back to Chapter 1 and review the section that listed the different aspects of object-oriented programming, you will see that you already know how most of them apply to JavaScript. You know what objects, methods, and properties are. You know that there are no classes in JavaScript, although you can fake them with constructor functions. Encapsulation? Yes, the objects encapsulate both the data and the means (methods) to do something with the data. Aggregation? Sure, an object can contain other objects. Actually, this is almost always the case as methods are functions, and functions are also objects. Now let's focus on the inheritance part. This is one of the most interesting features, as it allows you to reuse existing code, thus promoting laziness, which is probably what brought us to computer programming in the first place.

JavaScript is a dynamic language and there is usually more than one way to achieve any given task. Inheritance is not an exception to...