ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
arguments.callee属性用于返回当前正在执行的Function对象。 ## 语法 ``` [functionObject.]arguments.callee ``` ## 返回值 arguments.callee属性的值为Function类型,返回当前正在执行的函数。 简而言之,arguments.callee 返回该 arguments 对象所属的函数。 arguments.callee属性是arguments对象的一个成员,该属性仅当相关函数正在执行时才可用。 arguments.callee属性的初始值是正被执行的Function对象。这将允许匿名函数成为递归的。 ## 示例&说明 ``` function test(){ // "test."可以省略 document.writeln( test.arguments.callee ); // function test(){ document.writeln( arguments.callee ); document.writeln( arguments.callee === test ); } // arguments.callee 就是当前执行函数的自身 document.writeln( arguments.callee === test ); // true }; test(); // 输出斐波那契数列(1,2,3,5,8,13……)第10项的数字 // 内部使用匿名函数+函数递归来实现 // 由于是匿名函数,在函数内部无法通过函数名来递归调用该函数 // 我们可以通过arguments.callee来取得当前匿名函数,从而进行递归调用 document.writeln(function(n){ if(n <= 2) return n; else return arguments.callee(n - 1) + arguments.callee(n - 1); }(10)); ```