//---------------------------class var Father = function(){ alert("Father**"); } Father.prototype.constructor = function(){ alert("**"); }; var f = new Father();//为什么是打印 Father** 而不是**呢,已经更新了构造函数了啊? alert(f.constructor);//的确是更新后的构造函数
这样写实不行的,改成下面的样子: var Father = function(){ alert("Father**"); } var Son=Father.prototype.constructor = function(){ alert("**"); }; var f = new Son();//要创建子类的实例 alert(f.constructor());//constructor是一个方法,加()
var Father = function(){
alert("Father**");
}
var Son=Father.prototype.constructor = function(){
alert("**");
};
var f = new Son();//要创建子类的实例
alert(f.constructor());//constructor是一个方法,加()
这个constructor就好像你给你家小狗按一个狗牌,用来说明这是你的狗。别人可以把这个狗牌摘下来按上新的狗牌,但是这却不能改变着个小狗还是你的 这个事实。