一、caller: 返回对现有函数的引用者/调用者
使用语法: 函数名.caller(返回对现有函数的引用者);
前提: 只有函数执行时才会有用
outFn();
function outFn() {
inFn();
console.log("我是第一个函数");
}
function inFn() {
console.log(inFn.caller);
因为outFn在调用inFn函数,所以通过inFn.caller得到的就是outFn的引用。
console.log("我是第二个函数");
}
outFn();
function outFn() {
console.log("我是第一个函数");
}
inFn();
如果一个函数是在全局作用域被调用(也就是没有其他含在调用这个函数)
那么,通过函数名caller得到的就是null。
function inFn() {
console.log(inFn.caller);
}
二、callee: 返回当前函数自身的引用
使用语法: 是arguments下的一个属性: arguments.callee;
三、arguments.callee: 有一个length属性获取形参的个数
outFn();
function outFn() {
inFn();
}
function inFn() {
console.log(arguments.callee);
}
function test(a,b,c) {
console.log(arguments.length);//获取实参个数
console.log(arguments.callee.length);//获取形参个数
console.log(test.length);//获取形参个数
}
test(1,2);