From: http://blog.iecn.net/zmm <script language="javascript"> function getFuncName(_callee) { var _text = _callee.toString(); var _scriptArr = document.scripts; for (var i=0; i<_scriptArr.length; i++) { var _start = _scriptArr[i].text.indexOf(_text); if (_start != -1) { if (/^functions*(.*).*rn/.test(_text)) { var _tempArr = _scriptArr[i].text.substr(0, _start).split('rn'); return _tempArr[_tempArr.length - 1].replace(/(var)|(s*)/g, '').replace(/=/g, ''); } else { return _text.match(/^functions*([^(]+).*rn/)[1]; } } } } function a() { return getFuncName(arguments.callee); } var b = function() { return getFuncName(arguments.callee); } window.alert(a()); window.alert(b()); </script>
推荐阅读
关于键盘事件中keyCode、which和charCode 的兼容性测试
测试结果:在IE下:>> 支持keyCode>> 不支持which和charCode,二者值为 undefined在Firefox下:>> 支持keyCode,除功能键外,其他键值始终为 0>> 支持which和charCode,二者的值相同在Opera下:>> 支持keyCode和whi>>>详细阅读
本文标题:获取Javscript执行函数名称的方法
地址:http://www.17bianji.com/kaifa2/JS/31211.html
1/2 1