日期:2014-05-16 浏览次数:20428 次
function A(text,value) { var num=0; this.GetNum=function(){return num;}; this.AddNum=function(){++num;} this.Text=text; this.Value=value; } var obj=new A("Hi","World"); var num; obj.AddNum(); num=obj.GetNum();//此时num应为1; obj.AddNum(); num=obj.GetNum();//此时num应为2;
var obj=new A("Hi","World"); obj.Text="Hello";//这一句执行完后num自动加一(用 = 赋值时能执行其它语句) num=obj.GetNum();//此时num应为1;
function A(text,value) { var num=0; this.GetNum=function(){return num;}; this.AddNum=function(){++num;} this.SetText = function(txt){ this.Text = txt; this.AddNum();}; this.Text=text; this.Value=value; } var obj=new A("Hi","World"); obj.SetText("Hello");//这一句执行完后num自动加一(用 = 赋值时能执行其它语句) num=obj.GetNum();//此时num应为1;