---
title: Object Prototypes
description: "> All JavaScript objects inherit properties and methods from a prototype. --- In the previous chapter we learned how to use an **object constructor**: ### Example `function Person(first, last, age, eyecolor) { this.firstName = first; this.lastName = last; this.age = age;…"
url: "https://apprentice.mn/docs/object-prototypes/"
updated: "2021-05-18"
category: Javascript
---

# Object Prototypes

> All JavaScript objects inherit properties and methods from a prototype.

---

In the previous chapter we learned how to use an **object constructor**:

### Example

      `function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");`

We also learned that you can **not** add a new property to an existing object constructor:

### Example

      `Person.nationality = "English";`

To add a new property to a constructor, you must add it to the constructor function:

### Example

      `function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
  this.nationality = "English";
}`

## Prototype Inheritance

All JavaScript objects inherit properties and methods from a prototype:

- `Date` objects inherit from `Date.prototype`
- `Array` objects inherit from `Array.prototype`
- `Person` objects inherit from `Person.prototype`

The `Object.prototype` is on the top of the prototype inheritance chain:

`Date` objects, `Array` objects, and `Person` objects inherit from `Object.prototype`.

---

## Adding Properties and Methods to Objects

Sometimes you want to add new properties (or methods) to all existing objects of a given type.

Sometimes you want to add new properties (or methods) to an object constructor.

---

## Using the **prototype** Property

The JavaScript `prototype` property allows you to add new properties to object constructors:

### Example

      `function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

Person.prototype.nationality = "English";`

The JavaScript `prototype` property also allows you to add new methods to objects constructors:

### Example

      `function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

Person.prototype.name = function() {
  return this.firstName + " " + this.lastName;
};`

Only modify your **own** prototypes. Never modify the prototypes of standard JavaScript objects.

         [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-prototypes%2F&linkname=Object%20Prototypes)[https://www.addtoany.com/share](https://www.addtoany.com/share)
