Javascript匿名函数定义及举例?
来源:百度知道 编辑:UC知道 时间:2024/06/14 07:33:53
问下定义,然后举一个例子。谢谢
就是没有函数名的函数,一经定义,无法被其它程序段使用(因为没有函数名)
举例:
var a;
a.b = function(){alert('hello');}
这时你要调用那个函数,就必须用a.b的方式访问,而不像普通的函数,
在c#2.0也有匿名函数,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
(function(msg){
alert(msg);
})("第一种")
function exec(fun, msg){
fun(msg);
}
exec(function(val