O'Reilly logo

Head First JavaScript Programming by Elisabeth Robson, Eric T. Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Extra strength objects

Using Prototypes

image with no caption

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...

image with no caption

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 based on prototypes. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required