//定义一个类
function TestClass(name)
{
//初始化时总数+1
TestClass.prototype.Count++;
//定义一个属性,并设置默认值
this.Name = name || "jxh";
//定义一个静态类属性
TestClass.prototype.Current.InternalName = this.Name;
//定义一个对象属性
this.internalClass = new InternalClass(this.Name);
//定义一个方法
this.GetFormatName = function()
{
var fname = this.internalClass.FormatName();
return fname;
}
}
//为TestClass类定义一个静态属性
TestClass.prototype.Count = 0;
//为TestClass类定义一个静态类属性
TestClass.prototype.Current = new InternalClass("没有实例");
//内部类
function InternalClass(name)
{
this.InternalName = name;
}
<script language = "javascript">
function Click_Event()
{
alert("没有实例对象");
alert("TestClass.prototype.Count:" + TestClass.prototype.Count);
alert("TestClass.prototype.Current:" + TestClass.prototype.Current.InternalName);
var testClass1 = new TestClass();
alert("实例1个对象");
alert("TestClass.prototype.Count:" + TestClass.prototype.Count);
alert("TestClass.prototype.Current:" + TestClass.prototype.Current.InternalName);
var testClass2 = new TestClass("jxhwei");
alert("实例2个对象");
alert("TestClass.prototype.Count:" + TestClass.prototype.Count);
alert("TestClass.prototype.Current:" + TestClass.prototype.Current.InternalName);
}
</script>


浙公网安备 33010602011771号