有没有办法从当前函数中获取当前函数? [英] Is there a way to get the current function from within the current function?
本文介绍了有没有办法从当前函数中获取当前函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var f1 = function(param1 ,param2){
//有没有办法获得'f1'
//(当前函数)的对象?
};
正如您所看到的,我想从一个匿名函数中访问当前函数。 p>
这可能吗?
解决方案
是 - arguments.callee
是当前函数。
注意:ECMAScript 5中不推荐使用,并且可能导致尾部递归性能下降等等。然而,它在大多数主流浏览器中都能正常工作。
在你的情况下, f1
也可以工作。
Sorry for the really weird title, but here’s what I’m trying to do:
var f1 = function (param1, param2) {
// Is there a way to get an object that is ‘f1’
// (the current function)?
};
As you can see, I would like to access the current function from within an anonymous function.
Is this possible?
解决方案
Yes – arguments.callee
is the current function.
NOTE: This is deprecated in ECMAScript 5, and may cause a performance hit for tail-call recursion and the like. However, it does work in most major browsers.
In your case, f1
will also work.
这篇关于有没有办法从当前函数中获取当前函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文