> For the complete documentation index, see [llms.txt](https://eleven-fifty-academy.gitbook.io/javascript-152-objects-arrays/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eleven-fifty-academy.gitbook.io/javascript-152-objects-arrays/04-objects/prototypes/prototypes-continued.md).

# Prototypes Continued

## The Prototype Property

While the prototype chain is pretty awesome, it can only be used to access certain properties/methods/functions (Which term or terms is best to use here?). There are really two ways to figure out which properties can be accessed: 1. Exactly what we did previously; typing the (prototype?) object name followed by a period `.` 2. Entering the name followed by `__.proto.__` or `.prototype`

* `__.proto.__` (two underscores on each side) is only used on the base of your prototype chain, `person1` in our case (correct?). You can use it to get a better understanding of the prototype chain's path.
* `.prototype` is used in every other link of the chain (correct?). Without it, you won't be able to use functions such as `isPrototypeOf` or `valueOf`. Please note that these are advanced topics and you probably won't need to go this much in depth for awhile.

## Object.create()

Remember earlier how we used something called `Object.create()` to create objects? Let's learn more about it now.

* Let's create a new object instance called`person2`.

  ```javascript
  var person2 = Object.create(person1);
  ```
* At first glance you may think something's up, it looks just like `person1`! While the data looks exactly the same (name, age, etc.), it's not really a copy, `person2` is just using `person1`'s prototype as a prototype object.
* You can confirm this by running `person2.__proto__`.

  ![person2.\_\_proto\_\_](https://github.com/eleven-fifty-academy/javascript-152-objects-arrays/tree/6af4c10b1e5f426783d62e4294dc69e2f210b2fd/assets/proto2.PNG)

  See, the `Person` object, `person1`'s prototype, is returned.

## The Constructor Property

There's also a `.constructor` property that allows you to see the properties available to object instances created using that constructor. For example, both `person1.constructor` and `person2.constructor` return: \
&#x20;

![Constructor](https://github.com/eleven-fifty-academy/javascript-152-objects-arrays/tree/6af4c10b1e5f426783d62e4294dc69e2f210b2fd/assets/Constructor.PNG)

&#x20;\
&#x20;the `Person()` constructor.

If for some reason you don't have a reference to the original constructor and want to create a new reference, you're in luck! You can create a new instance like so:

```javascript
var person3 = new person1.constructor('Karen', 'Stephenson', 26, 'female', ['playing drums', 'mountain climbing']);
```

The `.constructor` property can also help you find the constructor name based on an instance name, for example:

```javascript
person1.constructor.name
```

returns **"Person"**.

## Modifying Prototypes

If you really needed to modify the `.prototype` property, you can. Let's add a goodbye message to our code.

```javascript
Person.prototype.farewell = function() {
  alert(this.name.first + ' has left the building. Bye for now!');
};
```

`person1.farewell()` returns the following:&#x20;

![Farewell](https://github.com/eleven-fifty-academy/javascript-152-objects-arrays/tree/6af4c10b1e5f426783d62e4294dc69e2f210b2fd/assets/Farewell.PNG)

&#x20;\
&#x20;You shouldn't use this concept often however. For example:

```javascript
Person.prototype.fullName = 'Bob Smith';
```

This doesn't work because it's not that flexible. Even something like this

```javascript
Person.prototype.fullName = this.name.first + ' ' + this.name.last;
```

would give you `undefined` because the global scope is being referenced rather than the function scope.

Moral of the story is: If you really want to define properties on the **prototype** make sure they are **static, constant** properties. Otherwise, it's generally best to just define them on the **constructor**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://eleven-fifty-academy.gitbook.io/javascript-152-objects-arrays/04-objects/prototypes/prototypes-continued.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
