Kế thừa ngang giữa 2 object
https://js.edu.vn/7-ke-thua-prototype-ngang-va-doc.html
Kế thừa ngang giữa 2 object
Có 2 cách: __proto__ và Object.create. Quan sát ví dụ:

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ày01020304050607080910111213141516
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.prototypeKế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
Last updated
Was this helpful?