当前位置:编程学习 > JAVA >>

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 


摘自  万一的 Delphi 博客
 
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,