<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP ‘test3.jsp‘ starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="js/jquery-2.1.1.min.js"></script>
<script>
//函数参数
//js的参数:形参,实参
function test(a,b){
//alert(test.length); //参数名.length可以得到函数参数个数(并不一定等同于实际传入的参数个数)
//函数的实际参数 内部是通过数组的形式接收实际参数
//arguments对象可以访问函数的实际参数 arguments只能在函数内部使用
//alert(arguments.length); //返回实际传入的参数
//alert(arguments[0]);
//alert(arguments[1]);
// if(arguments.length===test.length){
// return a+b;
// }else{
// return ‘参数不正确‘;
// }
//arguments对象用的做多的还是递归操作 arguments.callee指向函数本身
alert(arguments.callee.length); //arguments.callee.length得到的值和函数名.length值相同,但是arguments.callee.lenth更好
return a+b;
}
//alert(test(1,2)); //3
//alert(test(1,2,3,4)); //3
//alert(test()); //NaN
function fact(num){
if(num<=1){
return 1;
}else{
//return num*fact(num-1);
return num*arguments.callee(num-1); //等同于return num*fact(num-1);
}
}
var F=fact;
alert(fact(5));
fact=null; //如果此处fact=null,函数写成return num*fact(num-1);会报错,但return num*arguments.callee(num-1); 正确
alert(F(5));
</script>
</head>
<body>
This is my JSP page. <br>
</body>
</html>本文出自 “matengbing” 博客,请务必保留此出处http://matengbing.blog.51cto.com/11395502/1879001
原文地址:http://matengbing.blog.51cto.com/11395502/1879001