Javascript系列教程:面向对象讲解(三)

  • 发表于
  • jQuery

对象的访问修饰条符

<script type="text/javascript">
function Person(){
var Name="Wang Hongjian";
var Age=22;//私有成员
this.Age=23;//公有成员

var Job="工程师";//局部成员
this.GetJob=function(){
return Job;
}
alert(Age);
alert(this.Age);
}
var P=new Person();
alert(P.Age);//访问公共成员
alert(P.GetJob());
</script>

当然其中也可通过

this.GetAge=function(){
return this.Age;
}

来访问其公共成员.