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

Summary


Let's summarize the most important topics you have learned in this chapter.

  • All functions have a property called prototype. Initially it contains an empty object.

  • You can add properties and methods to the prototype object. You can even replace it completely with an object of your choice.

  • When you create objects using a function as a constructor (with new), the objects will have a secret link pointing to their prototype, and can access the prototype's properties as their own.

  • Own properties take precedence over prototype's properties with the same name.

  • Use the hasOwnProperty() method to differentiate between own properties and prototype properties.

  • There is a prototype chain: if your object foo doesn't have a property bar, when you do foo.bar, JavaScript will look for a bar property of the prototype. If none is found, it will keep searching in the prototype's prototype, then the prototype of the prototype's prototype and keep going all the way up to the highest-level parent Object....