不小心拷多了个时间在里面,正确代码如下:
<script type="text/javascript">
function NewObj()
{
this.a=new Array();
this.Items=function()
{
return this.a;
}
this.b=function(name)
{
if(name=="")
return;
this.a.push(name);
}
}
function test()
{
var tObj=new NewObj();
tObj.b("c");
alert("Items.length="+tObj.Items.length+" a.length="+tObj.a.length);
}
</script>
<input type="button" value="test" onclick="test()">
<script type="text/javascript">
function NewObj()
{
this.a=new Array();
this.Items=function()
{
return this.a;
}
this.b=function(name)
{
if(name=="")
return;
this.a.push(name);
}
}
function test()
{
var tObj=new NewObj();
tObj.b("c");
alert("Items.length="+tObj.Items.length+" a.length="+tObj.a.length);
}
</script>
<input type="button" value="test" onclick="test()">
====>
alert("Items.length="+tObj.Items().length+" a.length="+tObj.a.length);
function NewObj()
{
this.a=new Array();
this.Items=function(a)
{
return this.a;
}
this.b=function(name)
{
if(name=="")
return;
this.a.push(name);
}
}
function test()
{
var tObj=new NewObj();
tObj.b("c");
alert("Items.length="+tObj.Items.length+" a.length="+tObj.a.length);
}
</script>
<input type="button" value="test" onclick="test()">
-----------------------------------------------------------------------
这样就行了,上面加上a