js 获取函数的函数名称单个(只能获取一个):
function fun_name (num){
var tmp = arguments.callee.toString();
var re = /function\s*(\w*)/ig;
var matches = re.exec(tmp); //正则原因只能获取一个,获取多个需循环获取 函数形式 function xxx()
alert(matches[1]);
}
fun_name();
参考网站:http://www.zhixing123.cn/jsp/37819.html
http://segmentfault.com/q/1010000000154237
js获取函数名称的多个获取方法:
function fun_names(){
var tmp = arguments.callee.toString();
var re = /([a-zA-Z0-9_.]*)\s*=\s*function\s*\(/ig;
var tmpx = [];
while(r = re.exec(tmp))
{
tmpx.push(r[1]);
}
console.log(tmpx);
}
<pre name="code" class="javascript">fun_names();
参考网站: http://nece001.blog.163.com/blog/static/8563360201211044415884/ (JS正则获取文本中的多个匹配)