function MyObject(){}
Array.prototype={};
MyObject.prototype={};
var a=new Array();
var b=new MyObject();
alert(a.constructor==Array);//true
alert(b.constructor==MyObject);//false
function MyObject(){} Array.prototype={}; MyObject.prototype={}; var a=new Array(); var b=new MyObject(); alert(a.constructor==Array);//true alert(b.constructor==MyObject);//false
Share
Array.prototypeis a non-writable property.As such, your assignment:
…doesn’t succeed, and so its
.constructorproperty hasn’t changed.15.4.3.1 Array.prototype
…whereas with your custom constructor, you have the ability to assign a different prototype object, so you’ve overwritten the original which had reference to the constructor via
.constructor.