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

2010年6月28日 热度:43 ℃ 发表评论 阅读评论

对象的访问修饰条符

<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;
}

来访问其公共成员.

声明: 本文采用 BY-NC-SA 协议进行授权. 转载请注明转自: Javascript系列教程:面向对象讲解(三)
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

加载中……