I javascript
A novice, recently encountered a problem that I have been unable to understand, as follows:
var A = function() {
return new B()
}
var B = function() {
this.name = "B"
}
var a = A()
console.log(Object.getPrototypeOf(a) == B.prototype) // true
var C = function() {
return new C()
}
var c = C() //
the personal confusion is why returning your own instance in one constructor will show a stack overflow, but there is no problem returning instances of other constructors.
in addition, as far as I understand, whether the constructor returns its own instance is somewhat similar to recursion , so it returns an error, but what is returned is that an instance object should not continue to make its own calls, so how to understand it? I can"t figure it out all the time.
I hope there are seniors who can give us some advice. Thank you!