callee 与 caller

arguments.callee 在函数内部指向函数本身

1.函数调用

function sum (num){
if(num <= 1){
return 1;
}else{
return num * (arguments.callee(num - 1))
}
}

2.区分形参

function a(num1,num2,num3){
console.log(arguments.length);//实参长度为1
console.log(arguments.callee.length);//行参长度为3
}
a(0);

call  返回被调函数执行环境

function a(){ fun(); function fun(){ console.log(fun.caller)//这里必须写在fun里面,因为caller只有函数执行过程中才有效 } } a();

 // fn a

猜你喜欢

转载自www.cnblogs.com/justSmile2/p/9822199.html