日期:2014-05-16 浏览次数:20356 次
function functionName(arg0, arg1, ... argN) { statements }
<html> <head> <title>正常方法</title> <script type="text/javascript"> function print(msg) { document.write(msg,"<br/>"); } </script> </head> <body> <script type="text/javascript"> alert(print("没有return"));//输出undefined </script> </body> </html>
<html> <head> <title>函数重载</title> <script type="text/javascript"> function print(msg){//函数1 document.write(msg,"<br/>"); } function print(){//函数2 alert("first parameter:" + arguments[0]); } </script> </head> <body> <script type="text/javascript"> print("正常方法"); </script> </body> </html>
print("正常方法");
print("正常方法");
function sayHi(sName, sMessage) { alert("Hello " + sName + sMessage); }
var sayHi = new Function("sName", "sMessage", "alert(\"Hello \" + sName + sMessage);");
var doAdd = new Function("iNum", "alert(iNum + 20)"); doAdd = new Function("iNum", "alert(iNum + 10)"); doAdd(10);
var doAdd = new Function("iNum", "alert(iNum + 10)"); var alsodoAdd = doAdd; doAdd(10); //输出 "20" alsodoAdd(10); //输出 "20"
function callAnotherFunc(fnFunction, vArgument) { fnFunction(vArgument); } var doAdd = new Function("iNum", "alert(iNum + 10)"); callAnotherFunc(doAdd, 10); //输出 "20"
function doAdd(iNum) { alert(iNum + 10); } function sayHi() { alert("Hi"); } alert(doAdd.length); //输出 "1" alert(sayHi.length); //输出 "0"