guanxf

我的博客:http://blog.sina.com.cn/17learning

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  71 随笔 :: 1 文章 :: 41 评论 :: 0 Trackbacks
function Person(){
  var  age=0;//定义私有成员变量age
  function checkAge(age){
     if(age<0 && age>150){
         return false;
     }
     return true;
  }
this.setAge=function(theAge){
  if(checkAge(theAge)){
     age=theAge;    
  }else{
     alert("please input cuerrent age!");
  }
}
this.getAge=function(){
     document.write(age);
     return age;
}
}
var per=new Person();
per.setAge(122);
per.getAge();
posted on 2011-12-15 00:56 管先飞 阅读(1267) 评论(1)  编辑  收藏

评论

# re: js封装属性和方法 2014-11-10 11:23 21
213312  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: