JavaScript 演练(6). 函数的定义与自执行
/* 函数的定义 */
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