Why does prototype inheritance in the prototype chain have such a different result?

< H2 > purpose: < / H2 >
ABBCBObjectC?
< H2 > my understanding: < / H2 >
prototypenew B(),Anew B()__proto__BBnew C() ?

the first way to write:


:


Mar.13,2021

js has variable improvement, so the first paragraph is equivalent to

function A () {
  
}
function B () {

}
function C () {
  
}
var aObj;
A.prototype = new B(); // ABobject
A.prototype.constructor = A;

B.prototype = new C();
B.prototype.constructor = B; // B

// A.prototype = new B(); // newBC.prototype

aObj = new A();
console.log(aObj);

Update:
your puzzle may be that if I change the prototype property of a method, will the original new object automatically update the prototype object?

function B () {}
let b = new B()
console.log(b.__proto__ === B.prototype) // true
B.prototype = {} // B
console.log(b.__proto__ === B.prototype) // falsenew

Abstract the above process and change it to the following:

console.log(b.__proto__ === B.prototype) // true
B.prototype = {} // B
console.log(b.__proto__ === B.prototype) // false

simplify, use c instead of b.protoplast , d instead of B.prototype :

console.log(c === d) // true
d = {}
console.log(c === d) // false

that is, at first c and d point to the same object, and then make d point to another object, then will c automatically update to point to the new object?
answer: why is it updated automatically?

Menu