javascript中用函数属性实现函数调用计数
<script>
test.counter = 0;
function test(a,b,c)
{
test.counter++;
alert(test.counter);
}
setTimeout("alert(test.counter)",5000);
</script>
</HEAD>
<BODY>
<a href="javascript:void window.open();">link</a>
<input type=button value="test" onclick="javascript:test();">
test.counter = 0;
function test(a,b,c)
{
test.counter++;
alert(test.counter);
}
setTimeout("alert(test.counter)",5000);
</script>
</HEAD>
<BODY>
<a href="javascript:void window.open();">link</a>
<input type=button value="test" onclick="javascript:test();">
test.counter为函数属性,函数每被调用一次,计数加一。
但还不明白函数属性和全局变量有啥不一样?
貌似一样。。。。。。