# [JavaScript] Object-Oriented Programming (OOP) with JavaScript : Prototypal Inheritance on Built-in Objects (feat. prototype chain)

```
console.log(jonas.__proto__); // prototype of jonas
```

![prototype chain 1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520238257/7S6K859ry.PNG align="left")

```
console.log(jonas.__proto__.__proto__); // top of the prototype chain
console.log(jonas.__proto__.__proto__.__proto__); // null
```

![prototype chain 2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520295694/KJr55a-av.PNG align="left")

```
console.dir(Person.prototype.constructor);
```

![prototype chain 3.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520352921/wOzNbAB9H.PNG align="left")


```
const arr = [3, 6, 4, 5, 6, 9, 3]; // new Array === []
console.log(arr.__proto__);
console.log(arr.__proto__ === Array.prototype);
```

![prototype chain 4.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520531410/9nj6SOkHI.PNG align="left")

```
console.log(arr.__proto__.__proto__);
```

![prototype chain 5.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520570556/6Q4akXAkw.PNG align="left")

```
Array.prototype.unique = function () {
  return [...new Set(this)];
};

console.log(arr.unique());
```

![prototype chain 6.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520630000/G2keS3JyX.PNG align="left")

- This is not a good way to add a prototype method. 
Because 1. JavaScript could update the method with the same name, then the bug can occur. 2. other developers in the team can use the same name, then it also can make some bugs.

```
// check prototype chains and inheritance
const h1 = document.querySelector('h1');
console.dir(x => x + 1);
```

![prototype chain 7.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658520921957/C9UvLvOpO.PNG align="left")
- It is a huge prototype chain. 
