日期:2014-05-16 浏览次数:20417 次
<script> function box(){ var user; this.getuser=function(){ return user; }; box.prototype.setuser=function(value){ user=value; }; } var b1=new box(); var b2=new box(); var b3=new box(); b1.setuser('www'); alert(b1.getuser()); alert(b2.getuser()); alert(b3.getuser()); </script> 最近在学js面向对象与原型 结果:undefined undefined 'www' 求大神解释
function box(){ var user; this.getuser=function(){ return user; }; box.prototype.setuser=function(value){ user=value; }; } var b1=new box(); var b3=new box();////// var b2=new box();////// b2.setuser('www'); alert(b1.getuser()); alert(b2.getuser()); alert(b3.getuser());