日期:2014-05-16 浏览次数:20349 次
<html>
<title></title>
<head>
?
<script type="text/javascript">
?(function(msg) {
???? alert(msg);
? })('hello');
</script>
</head>
</html>
?
?
以上代码将会弹出hello窗口
?
以上代码实际上是定义了一个匿名函数,并且调用了该匿名函数
var closure = (function() { var a = 3; return function() { alert(a); }; })(); closure();//3
var closure = (function() { var a = 3; return function() { alert(a); }; })(); closure();//3
var closure = function() { var a = 3; return function() { alert(a); }; }; closure();//3
var closure = (function() { var a = 3; return function() { alert(a); }; })(); closure();//3
var closure = function() { var a = 3; return function() { alert(a); }; }; closure();//3
var closure = (function() { var a = 3; return function() { alert(a); }; })(); closure();//3
var closure = function() { var a = 3; return function() { alert(a); }; }; closure();//3