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

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Grow your business fast with

Suku