日期:2014-05-16 浏览次数:20438 次
<script type="text/javascript">
function Cons(){ //声明构造函数 Cons()
Cons.prototype.info="something";
Cons.prototype.showInfo=function(){
alert(this.info);
}
}
Cons.prototype.info="changed!"; //尝试修改原型中的属性
var inst=new Cons(); //建立实例 inst
inst.showInfo(); //修改无效,警告"something"
</script>
//... var inst=new Cons(); //建立实例 inst Cons.prototype.info="changed!"; //尝试修改原型中的属性 inst.showInfo(); //警告"changed!" //...
<script type="text/javascript">
function Cons(){ //声明构造函数 Cons()
Cons.prototype.info="something";
Cons.prototype.showInfo=function(){
alert(this.info);
}
}
Cons.prototype.newInfo="new!"; //尝试在原型中添加属性
var inst=new Cons(); //建立实例 inst
alert(inst.newInfo); //有效,警告"new!"
</script>