作者dreamerslab (dreamerslab)
看板Ajax
标题Re: [问题] 在Function中取得Function Name
时间Thu Feb 10 13:46:10 2011
※ 引述《IwillSay (我将会)》之铭言:
: 请问假如我有一个object长这样
: var fns = {
: MethodA : function() {
: //alert(???); 在这边取得MethodA的字串
: }
: };
: 请问有办法在MethodA里面取得他对应的Property Name吗(MethodA)
除非你给这个function一个名字
就可以像下面抓出来
var fns = {
MethodA : function MethodA(){
var tmp = /\W*function\s+([\w\$]+)\(/.exec(arguments.callee.toString()),
functionName = tmp !== null ? tmp[ 1 ] : 'anonymous';
alert(functionName);
}
};
fns.MethodA();
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.192.49.219