HTML and CSS Reference
In-Depth Information
Once the instance is populated with the appropriate properties, you can use the methods
defined on the prototype:
> p1.getFullName()
"John Smith"
Notice that the references to this inside the prototype now refer to the object itself and the
full name of the person is returned.
JavaScript is a type of object orientated language called a “prototype-based language”. Pro-
totype languages use existing objects as the basis for new objects, which are then modi-
fied to meet their specific needs. The fact that JavaScript also supports syntax for creating
Class-like structures sometimes obscures this fact.
Prototype-based languages look unfamiliar to most people who have used other classical
object orientated languages such as C++ or Java. The approach is very powerful however,
and the examples in this topic will favour prototypes to classes as the basic approach to
code reuse.
Prototype-based object orientated languages are relatively rare, which is why they are so
unfamiliar. Other than languages based on JavaScript, it is unlikely most software en-
gineers will ever encounter another prototype-based language. In order to succeed with
JavaScript it is important to be aware of its fundamental nature however, and embrace it
rather than fight it.
Search WWH ::

Custom Search