caller返回调用当前函数的引用,如果是函数自身调用,则返回null,callee返回正在被执行函数的引用,即返回函数自身
function callerFun(){
console.log(callerFun.caller);
}
function a()
{
callerFun();
}
a();
console.log("---------------------------------------------------")
callerFun();
console.log("---------------------------------------------------")
function calleeFun(x,y) {
console.log(arguments.length,arguments.callee.length,arguments.callee)
} ;
calleeFun(1,2,3) ;
执行结果:
ƒ a()
{
callerFun();
}
callerTest:9 ---------------------------------------------------
callerTest:2 null
callerTest:11 ---------------------------------------------------
callerTest:17 3 2 ƒ calleeFun(x,y) {
console.log(arguments.length,arguments.callee.length,arguments.callee)
}
callerTest:1 undefined
网友评论