var ParentObj = function(){
this.say = function(){
console.log('parent');
}
};
var ChildObj = function(){
this.say = function(){
console.log('child');
};
};
//ChildObj.prototype 不等于 ChildObj or Object
//ChildObj.prototype.constructor === ChildObj 这个是对的
//console.log(ChildObj.prototype == new Object);
//执行delete ChildObj.prototype.constructor ;之后,ChildObj.prototype.constructor == Object为真,在类创建以后,prototype指向的是Object的一个实例,但是constructor赋值为当前对象,当使用delete删除以后,就会使constructor指向Object
//因此函数和构造器的区别在于prototype属相是否指向一个有意义的值,其他的没有本质区别
//console.log(ChildObj.prototype.constructor == Object);
//ChildObj.prototype = new ParentObj();
var p = new ParentObj();
var c = new ChildObj();
//在初始的状态下,p.constructor == ParentObj 为true对象实例的constructor指向构造器
//在ChildObj.prototype = new ParentObj();的情况下p.constructor == c.constructor为true
console.log(p.constructor == c.constructor );
版权声明:本文为博主原创文章,未经博主允许不得转载。