Javascript prototype and Object.create () inheritance?

Something confuses me in prototyping in JS.

Suppose I have an object like this:

let a = {
  b: 1
};
Run codeHide result

Now I want to create another object that inherits the properties of 'a'.

let obj = Object.create(a);
Run codeHide result

So, in this situation, I will link the proto of my 'obj' with the proto of 'a', which will reference Object.prototype. The first question is whether the link removes obj. proto to replace with. proto ?

Now let's assume that:

I would think that it updates the "a" in memory by deleting its links.

So, if I do this:

a.isPrototypeOf(obj)
Run codeHide result

false. "obj" b (obj.b print 1). ?

+4
1

, , . , .

var x = { a:10 }
var y = { x };
x = 10;

, y 10 x. , , , . x .

, a, . , isPrototypeOf(obj) - a.

0

Source: https://habr.com/ru/post/1664756/


All Articles