# Kế thừa ngang giữa 2 object

**Kế thừa ngang giữa 2 object**

Có 2 cách: \_\_proto\_\_ và Object.create. Quan sát ví dụ:

![](http://js.edu.vn/wp-content/uploads/2019/01/Screenshot-2019-01-08-02.46.30.png)

```
Tình cờ tìm được minh họa sau từ trang mollypages:

Còn đây là một minh họa khác trên StackOverFlow, minh hoạt cho code này
```

| 01020304050607080910111213141516 | `Object.O1='';Object.prototype.Op1='';` `Function.F1 =` `'';Function.prototype.Fp1 =` `'';` `Cat =` `function(){};Cat.C1 =` `'';Cat.prototype.Cp1 =` `'';` `mycat =` `new` `Cat();o = {};` `// EDITED: using console.dir now instead of console.logconsole.dir(mycat);console.dir(o);` |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

```
 
Một minh họa khác cho code sau:
```

| 010203040506070809101112 | `function` `Gadget(name, color){   this.name = name;   this.color = color;}` `Gadget.prototype.rating = 3` `var` `newtoy =` `new` `Gadget("webcam",` `"black")` `newtoy.constructor.prototype.constructor.prototype.constructor.prototype` `//trả về 3newtoy.__proto__.__proto__.__proto__// trả về null` |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

```
Code trên có sự khác nhau giữa __proto__ và constructor.prototype
```

```
Kết luận đáng chú ý:
```

| 1 | `The most surprising thing for me was discovering that Object.__proto__ points to Function.prototype, instead of Object.prototype.` |
| - | ----------------------------------------------------------------------------------------------------------------------------------- |

**Về sự khác biệt giữa \_\_proto\_\_ và prototype**
