-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Object-Oriented JavaScript
If you are new to the OO programming lingo and you're not sure you've fully grasped the concepts above, don't worry. We'll look at some code and you'll see that, although they may seem complicated when just talking about high-level concepts, things are much simpler in practice.
Thus said, let's rehash the concepts once more.
|
Feature |
Illustrates concept |
|---|---|
|
Bob is a man (an object). |
objects |
|
Bob's date of birth is June 1st, 1980, gender: male, hair: black. |
properties |
|
Bob can eat, sleep, drink, dream, talk and calculate his age. |
methods |
|
Bob is an instance of class Programmer. |
class (in classical OOP) |
|
Bob is based on another object, called Programmer. |
prototype (in prototypal OOP) |
|
Bob holds data (such as birth date) and methods that work with the data (such as calculate age). |
encapsulation |
|
We don't need to know how the calculation method works internally. The object might have some private data, such as the number of days in February in a leap year, we don't know, nor do we want to know. |
information hiding |
|
Bob is part of a Web Dev Team object, together with Jill, a Designer object and Jack, a Project Manager object. |
aggregation, composition |
|
Designer, Project Manager and Programmer are all based on and extend a Person object. |
inheritance |
|
You can call the methods Bob:talk, Jill:talk and Jack:talk and they'll all work fine, albeit producing different results (Bob will probably talk more about performance, Jill about beauty and Jack about deadlines). Each object inherited the method talk from Person and customized it. |
polymorphism, method overriding |
Change the font size
Change margin width
Change background colour