At the bottom it says "Prototype," and if we expand it, we see:
<img src=https://codehs.com/tutorial/ryan/"https://codehs.com/uploads/03baaa9c69490ea02848ab39f7359b48">
Low and behold, if you look closely at the 2nd line under Prototype, you see the method `hasOwnProperty()` listed! Our `animal` object was able to call this method because it was in its prototype! This prototype is the default Object prototype.
<br>
<h2> The Communal Pantry: a Shared Prototype </h2>
If the case for using an object constructor for multiple objects isn't already convincing enough, then add a "shared object prototype" to that pro list. When you create multiple objects via the same constructor, all of those objects are linked to the same prototype. That's because all functions have a `prototype` property, and when the function is called as a constructor, the value becomes the prototype for the newly created object.
Think of the prototype as a communal pantry in an apartment building -- if one of the residents doesn't have their own spice (property or method), they can look to the communal pantry (prototype) and use what's there instead. All of the residents (individual objects), *inherit* supplies (properties and methods) from communal space (prototype).
<img src=https://codehs.com/tutorial/ryan/"https://codehs.com/uploads/65652667d161fe0c2630e56b913a2b75" >
This functionality is quite valuable, which we'll talk about why in a moment. Let's first learn how you can customize the prototype created by the constructor.
<br>
<h2> Customizing the Shared Constructor Prototype </h2>
As mentioned, the object constructor has a `.prototype` property that we can use to configure the prototype of the objects it creates. To add methods or properties to this prototype, it looks like: `constructorName.prototype.keyName = value`.
Here's a simple example to demonstrate the setup:
```javascript
function Animal(firstName, animalType) {
this.name = firstName;
this.type = animalType;
}
Animal.prototype.speak = function() {
console.log("Hi! My name is " + this.name + ". I am a " + this.type + ".");
}
let tracy = new Animal("Tracy", "turtle");
tracy.speak(); // prints "Hi! My name is Tracy. I am a turtle."
```
<br>
Notice that the `turtle` object does NOT have the speak method itself, but it is able to call the method because it was added to the `Animal` prototype. Just like defining the values in the constructor, you can use the `this` keyword to refer to the individual object. You have to be a little careful though, the method call (`speak()`) has to come after the line that adds the method to the prototype.
<hr>
Try running this example in the editor below. Can you add another method to the Animal prototype?">