How to get the name of the function executed by Javscript

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 (/^function\s*\(.*\).*\r\n/.test(_text)) {
var _tempArr = _scriptArr[i].text.substr(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(arguments.callee);
}

var b = function() {
return getFuncName(arguments.callee);
}

window.alert(a());
window.alert(b());
</script>

Source: http://www.verydemo.com/demo_c98_i10470.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326561729&siteId=291194637