Skip to main content

Prototypechain

let f = function () {
this.a = 1;
this.b = 2;
};
let o = new f(); // {a: 1, b: 2}


f.prototype.b = 3;
f.prototype.c = 4;

// {a: 1, b: 2} ---> {b: 3, c: 4} ---> Object.prototype ---> null

console.log(o.a); // 1

console.log(o.b); // 2

console.log(o.c); // 4

console.log(o.d); // undefined

__proto__ is the actual object that is used in the lookup chain to resolve methods, etc.

prototype is the object that is used to build __proto__ when you create an object with new

( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefined