Can a prototype chain get Object ()?

I read an article explaining what a prototype chain is.

It says that if I try to access an object, but it does not have it, the javascript engine will try it .constructor.propotype. If he does not have this, try .construtor.propotype.constructor.propotype. Until it finds the built-in Object () object.

But I am testing this:

function a() {}
b = new a();

then

c = b.constructor.prototype

I get an empty object a.

then

d = c.constructor.prototype

I get an empty object a.

These are loops. No matter how much .constructor.prototypeI call, it cannot find Object (). What's wrong? Don't I understand the prototype chain?

+3
source share
2 answers

JS OOP constructor prototype , . / . ., , .

, ( .constructor.prototype), Object, , function a(){} constructor prototype a. a; Chrome :

> function a(){}
undefined
> a.constructor.prototype
function Empty() {}
> a.constructor.prototype = Object.prototype
Object
> a.constructor.prototype
function Empty() {} // hmmmm, the assignment didn't take...

, , . .constructor.prototype, . , , , .constructor.prototype .__proto__:

function a(){}
b = new a();
b.__proto__ === Object.prototype; // false
b.__proto__.__proto__ === Object.prototype; // true since we reached the top of the prototype chain

, __proto__ , ES5 :

obj.__proto__ === Object.getPrototypeOf(obj);

, .__proto__ .

+2

, .

A - :

A.prototype.constructor === A

A :

A. .

() .

+1

All Articles