代码改变世界

js在类的方法中访问自己的属性

2012-11-24 10:26  crazy--liyang  阅读(304)  评论(0编辑  收藏  举报
在类的方法中访问自己的属性,Javascript对于公有属性和私有属性的访问方法有所不同,请大家看下面的代码
function Shape(ax,ay)
{
var x = 0 ;
var y = 0 ;
this .gx = 0 ;
this .gy = 0 ;
var init = function ()
{
x
 = ax; // 访问私有属性,直接写变量名即可 
y = ay;
this .gx = ax; // 访问公有属性,需要在变量名前加上this. 
this .gy = ay;
};

init();
}