Object-Oriented Programming with JavaScript, Part I: Inheritance - Doc JavaScript
Object-Oriented Programming with JavaScript, Part I: Inheritance
In this column we embark on a short series about Object-Oriented Programming (00P) with JavaScript. In Part I of this series, we will cover the fundamentals. We will show you how JavaScript fulfills one of the most important requirements from an object-oriented language: inheritance. The examples in this part will also demonstrate the other requirement: encapsulation. We'll leave the third requirement, polymorphism, to other parts of this series.
Although JavaScript is a scripting language, its support of object-oriented programming is quite impressive. Even though there are no classes and instances, there are objects, prototypes, and implicit inheritance. We will explain in detail how to emulate inheritance and how the superclass-subclass relationship is formed. Prototyping is the key to understanding the inheritance concept. We'll teach you how to establish prototyping, how to detect whether one object is a prototype of another object, and how JavaScript's model is different from Java's object-oriented programming. We'll also show you how to check several attributes of the object's properties.
The examples in this column are for JavaScript 1.1 and above, for both Internet Explorer and Netscape, unless noted otherwise.
In this column, you will learn:
- How to characterize an object-oriented programming language
- How to implement inheritance with functions
- How to implement inheritance with prototyping
- How to add properties after the object is created
- How to probe inheritance in NS with __proto__
- How to emulate instanceOf()
- How to classify and print objects
- How to query an object's properties
- How to compare JavaScript and Java
Next: How to characterize an object-oriented programming language
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: March 12, 2001
Revised: March 12, 2001
URL: https://www.webreference.com/js/column79/index.html