I am unable to understand this loop behavior of the javascript.
Can someone tell me why was it designed in this way? Is there any real use case of this behavior?
why this loop? { Newly created instance inherits properties from the prototype property of the constructor function object. prototype property of the constructor function is an object that keeps constructor property. constructor property is equal to the constructor function object. Again constructor function object keeps prototype property. }
instance1---inhertis(keeps)-->Prototype property of func()-->keep constructor property-->function object func-->keep prototype property.
var func = function(){};
var construct = func.prototype.constructor;
console.log(construct === func); //true
var instance1 = new func();
Updated: Even if in between i assigned something else, instanceof always returns true.
var func1 = function(){};
func1.prototype.constructor = 1;
var instance1 = new func1();
console.log(instance1 instanceof func1); //true
var func2 = function(){};
func2.prototype.constructor = 0;
var instance2 = new func2();
console.log(instance2 instanceof func2); //true
Sorry to ask 2 question in 1 but both may be related.