callee与caller

1、callee

arguments.callee表示当前函数,使用于递归

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

2、caller

表示调用当前函数的函数,没有父函数时为null

function parent(){
	console.log(parent.caller);
	child()
 }
 
function child(){
	console.log(child.caller)
}

  

猜你喜欢

转载自www.cnblogs.com/lhyhappy65/p/9207382.html