js的arguments,callee,caller,length,prototype属性 我用几个例子简单的介绍下这几个函数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript" >
function myFunc(arg1,arg2){};
alert(myFunc.length);//显示函数形参的个数 结果为2
//------------------------------
function myfunc2(){
var s="";
var len=arguments.length;
for (var i=0;i<len;i++){
s+=arguments[i];//此处要注意 arguments并非真正的数组,如果需要变为数组,下面有方式方法。
//var args=Array.prototype.slice.call(arguments);//将arguments转变成真正的数组,并赋予args
};
alert(s);
};
myfunc2(1,2,3);//结果为123
(function test(){
alert(arguments.callee);//arguments.callee指的就是函数自己 注意 callee是 arguments的属性,不是函数的的
})();
//------------------------------
function printStackTrace(fn){//此函数可以找到函数的调用轨迹
var s="";
while(fn.caller){
s+=fn.caller;//fn.caller查看函数的被调用者
s+="\n<--\n";
fn=fn.caller;
};
alert(s);
};
function test3(){
printStackTrace(test3);
};
function test2(){
test3();
};
function test1(){
test2();
};
function test0(){
test1();
};
test0();
//------------------------------
</script>
</body>
</html>


254

被折叠的 条评论
为什么被折叠?



