arguments.callee用法
2020-02-14 本文已影响0人
书虫和泰迪熊
argument.callee 在那个函数中运行,他就代表哪一个函数。一般用在匿名函数中。
在匿名函数中有时候需要自己调用自己,但是匿名函数没有名字,无名可调,此时就需要用arguments.callee 来代替匿名函数。
(function(n){
if(n > 1) return n* arguments.callee(n-1);
return n;
})(10);
argument.callee 在那个函数中运行,他就代表哪一个函数。一般用在匿名函数中。
在匿名函数中有时候需要自己调用自己,但是匿名函数没有名字,无名可调,此时就需要用arguments.callee 来代替匿名函数。
(function(n){
if(n > 1) return n* arguments.callee(n-1);
return n;
})(10);