您的位置:首页 > Web前端 > JavaScript

JavaScript 演练(6). 函数的定义与自执行

2012-03-15 18:13 295 查看
/* 函数的定义 */
function a() { return 1; }

var b = function () { return 1; };

var c = function d() { return 1; }; // d === undefined

var e = new Function("return 1;");

alert(typeof a); //function
alert(typeof b); //function
alert(typeof c); //function
alert(typeof d); //undefined
alert(typeof e); //function

alert(a() + b() + c() + e()); //4

/* 函数自执行 */
(function (a, b) { alert(a + b); }) (1, 2);        //3

(function (a, b) { alert(a + b); } (1, 2));        //3

var f = function (a, b) { alert(a + b); } (1, 2);  //3; f === undefined
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: