SoFunction
Updated on 2025-03-03

How to get the name of the Javascript execution function

From: /zmm
<script language="javascript">
 function getFuncName(_callee) {
 var _text = _callee.toString();
 var _scriptArr = ;
 for (var i=0; i<_scriptArr.length; i++) {
 var _start = _scriptArr[i].(_text);
 if (_start != -1) {
 if (/^function\s*\(.*\).*\r\n/.test(_text)) {
 var _tempArr = _scriptArr[i].(0, _start).split('\r\n'); 
 return _tempArr[_tempArr.length - 1].replace(/(var)|(\s*)/g, '').replace(/=/g, '');
 } else {
 return _text.match(/^function\s*([^\(]+).*\r\n/)[1];
 }
 }
 }
 }

 function a() {
 return getFuncName();
 }

 var b = function() {
 return getFuncName();
 }

 (a());
 (b());
</script>