Chapter 13. Extra strength objects
Using Prototypes
Learning how to create objects was just the beginning. Itâs time to put some muscle on our objects. We need more ways to create relationships between objects and to share code among them. And, we need ways to extend and enhance existing objects. In other words, we need more tools. In this chapter, youâre going to see that JavaScript has a very powerful object model, but one that is a bit different than the status quo object-oriented language. Rather than the typical class-based object-oriented system, JavaScript instead opts for a more powerful prototype model, where objects can inherit and extend the behavior of other objects. What is that good for? Youâll see soon enough. Letâs get started...
If youâre used to Java, C++, or any language based on classical object-oriented programming letâs have a quick chat.
And if you arenât... what, you got a date? Take a seat, and go along for the rideâyou might just learn something as well.
Weâll give it to you straight: JavaScript doesnât have a classical object-oriented model, where you create objects from classes. In fact, JavaScript doesnât have classes at all. In JavaScript, objects inherit behavior from other objects, which we call prototypal inheritance, or inheritance ...
Get Head First JavaScript Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.