Sunday, January 27, 2008

方法名做为另外一个函数的参数-闭包用法一

<html>
<head><title> test cloures </title></head>
<body>
<script type="text/javascript" charset="utf-8">
var a = b = 1; // var a = (b = 1), variable b is no declared(like var b, the scope of b is global.)
function test() {
alert("a=" + a); // 1
alert("b=" + b); // 10
return a + b;
}

function testClosures(funcName) {
var a = b = 10; // var a = (b = 10); b is a global variable.
return funcName();
}
alert(testClosures(test));
</script>
</body>
</html>

No comments :